Sponsored Content
Top Forums Shell Programming and Scripting How to build a command into a string rather than execute the command Post 302200671 by littlejon on Thursday 29th of May 2008 07:31:45 PM
Old 05-29-2008
How to build a command into a string rather than execute the command

I'm trying to populate a command line into a variable. It appears to be executing, instead. Here's an example:

mycmd=''
if ...; then
$mycmd='sudo '
fi
$mycmd=$mycmd 'sed -i prev s/aaa/bbb/' $myfile
res=`$mycmd`

(I'm also not sure of the best way to execute the command from the variable, either, so any corrections would be appreciated!)

Last edited by littlejon; 05-29-2008 at 08:56 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Plz Help : How to use write command to execute command on some other terminal

Hi Group , I m trying to execute commands on some other system using write command but inspite of executing the commands they r passed as simple messages. - i m writing >write user-id ! ls o ctrl-d inspite of executing the command ls,other terminal shows ! ls. Thnx in advance. (2 Replies)
Discussion started by: Aashish
2 Replies

2. Shell Programming and Scripting

how to? launch command with string of command line options

my description from another thread... here's my code: #!/bin/bash IFS=$'\n' function OutputName() { input=$1 echo $input input=`echo "$input" | sed -e 's/.//'` input=`echo "$input".avi` output_name=$input } if ]; then echo... (5 Replies)
Discussion started by: TinCanFury
5 Replies

3. Shell Programming and Scripting

Please help: Build a sed command and execute it in a script

I am using an array to store some data (keys e.g 47975081_1215781266128), it can be assumed that it is key to other data. I want extract data from a file based on a couple of keys (range) and store the resulting data in a variable using the following command: sed -n... (9 Replies)
Discussion started by: gugs
9 Replies

4. Shell Programming and Scripting

Select command to build menu

Hello everyone. I am using the select command to build a menu, here is my question: Is it possible to generate a menu which contains several sections and have a separator between the sections without having a selection number generated in front of the separator? This is a sample of what I would... (1 Reply)
Discussion started by: gio001
1 Replies

5. Shell Programming and Scripting

How to build a command in a script

Hi All I am trying to build a script that will take data from a tab separated file and use that to split up a quicktime file. So far the code is as follows #!/bin/sh #test parsing of data #fix excel file output returns cat $1 | tr "\r" "\n" > $1.fix printf "\n" >> $1.fix mv $1.fix $1 ... (3 Replies)
Discussion started by: babajuma
3 Replies

6. Shell Programming and Scripting

execute command stored in a string

Hi, Here's the problem I am facing. This is just an example: list_files.ksh ------------ dir=$1 match=$2 var="ls $dir | grep $match" files=`"$var"` I get the below error on executing the above script: ./list_files.ksh: ls /home/my_files | grep xml: not found I know I... (2 Replies)
Discussion started by: dips_ag
2 Replies

7. Shell Programming and Scripting

When i am trying to execute export command within a shell script it is saying command not found.

I am running the export command within a view to use that value inside my build script. But while executing it it is saying "export command not found" My code is as follows: -------------------------- #!/bin/sh user="test" DIR="/bldtmp/"$user VIEW="test.view1" echo "TMPDIR before export... (4 Replies)
Discussion started by: dchoudhury
4 Replies

8. Shell Programming and Scripting

Want to terminate command execution when string found in the command output

Hi Experts, I am very much new to linux scripting, I am currently working on reducing my manual work and hence writing a script to automate few task. I am running below command to snmpwalk the router.. snmpwalk -v 3 -u WANDL_SU -a MD5 -A vfipmpls -x DES -X VfIpMpLs -l authPriv... (19 Replies)
Discussion started by: Hanumant.madane
19 Replies

9. Shell Programming and Scripting

How to execute a command on each line of output from another command?

Hello :) new to bash not to programming. I have an on-going need to change the owning group on sets of files and directories from the one they were created with or changed to on update to the one they need to have going forward. find {target_root} -group wrong_group gets me a newline... (4 Replies)
Discussion started by: naftali
4 Replies

10. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies
DB_COMMAND(9)						   BSD Kernel Developer's Manual					     DB_COMMAND(9)

NAME
DB_COMMAND, DB_SHOW_COMMAND, DB_SHOW_ALL_COMMAND -- Extends the ddb command set. SYNOPSIS
#include <ddb/ddb.h> DB_COMMAND(command_name, command_function); DB_SHOW_COMMAND(command_name, command_function); DB_SHOW_ALL_COMMAND(command_name, command_function); DESCRIPTION
The DB_COMMAND() macro adds command_name to the list of top-level commands. Invoking command_name from ddb will call command_function. The DB_SHOW_COMMAND() and DB_SHOW_ALL_COMMAND() are roughly equivalent to DB_COMMAND() but in these cases, command_name is a sub-command of the ddb show command and show all command, respectively. The general command syntax: command[/modifier] address[,count], translates into the following parameters for command_function: addr The address passed to the command as an argument. have_addr A boolean value that is true if the addr field is valid. count The number of quad words starting at offset addr that the command must process. modif A pointer to the string of modifiers. That is, a series of symbols used to pass some options to the command. For example, the examine command will display words in decimal form if it is passed the modifier "d". EXAMPLE
In your module, the command is declared as: DB_COMMAND(mycmd, my_cmd_func) { if (have_addr) db_printf("Calling my command with address %p ", addr); } Then, when in ddb: db> mycmd 0x1000 Calling my command with address 0x1000 db> SEE ALSO
ddb(4) AUTHOR
This manual page was written by Guillaume Ballet <gballet@gmail.com>. BSD
August 27, 2008 BSD
All times are GMT -4. The time now is 12:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy