06-06-2011
Running multiple commands stored as a semi-colon separated string
Hi,
Is there a way in Korn Shell that I can run multiple commands stored as a semi-colon separated string, e.g.,
# vs="echo a; echo b;"
# $vs
a; echo b;
I want to be able to store commands in a variable, then run all of it once and pipe the whole output to another program without using any temporary file or storing the individual commands outputs in another shell variable.
I seem to be able to do this directly on command line prompt but why not using a variable:
> ( echo a; echo b ) | wc -l
2
> vs="( echo a; echo b )"
> $vs | wc -l
bash: (: command not found
0
> `$vs` | wc -l
bash: (: command not found
0
>
Thanks for any help.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Does anyone know how to get these two output lines into one colon ':' separated line with some unix command? Maybe nawk. I've tried to read the nawk and awk man pages but I don't get it right. Are these commands the one to use?
Output from find command:
#
/sw/tools/matlab/7.0.1/man... (2 Replies)
Discussion started by: tonlu
2 Replies
2. Programming
Hi All,
Is there anything wrong with below syntax?
qx {perldoc -v ModuleName.pm | grep -i Description }
BTW, this question is related to Perl.
Thanks. (3 Replies)
Discussion started by: jal_capri
3 Replies
3. Shell Programming and Scripting
What am I doing wrong here? Or is this not possible?
A bug?
alias f='find . >found 2>/dev/null &'
f ; sleep 20 ; ls -l
-bash: syntax error near unexpected token `;' (2 Replies)
Discussion started by: star_man
2 Replies
4. Shell Programming and Scripting
Hi All,
I need a unix script to convert .csv files to .skv files (changing a comma delimited file to a semi colon delimited file). I am a unix newbie and so don't know where to start. The script will be scheduled using cron and needs to convert each .csv file in a particular folder to a .skv... (4 Replies)
Discussion started by: CarpKing
4 Replies
5. Homework & Coursework Questions
After some thought.
I am uncomfortable issuing my professors name where, there may be unintended side effects from any negative responses/feedback. Willing to re post if I can omit school / professor publicly, but can message moderator for validation? I am here for knowledge and understanding,... (1 Reply)
Discussion started by: briandanielz
1 Replies
6. Shell Programming and Scripting
Hi All,
I have put a perl script together to go and collect some information from multiple nodes/endpoints. The script works absolutly fine however I want to make it quicker.
You will see in the below that my script calls an expect script called ssh_run_cmd2.exp followed by the IP of... (7 Replies)
Discussion started by: mutley2202
7 Replies
7. UNIX for Dummies Questions & Answers
Hi,
I need to filter my data based on items in column 23. Column 1 until column 23 are tab separated. This is how column 23 looks like:
PRIMARY=<0/1:504:499,5:.:.:.:0.01:1:15:.>
I want to extract lines if items 7 (separated by : ) in column 23 are more than 0.25 . In example above , item... (2 Replies)
Discussion started by: janshamsani
2 Replies
8. Shell Programming and Scripting
I am using awk to search $5 of the "input" file using the "list" file as the search criteria. So if the id in line 1 of "list" is found in "search" then it is counted in the ids found. However, if the line in "list" is not found in "search", then it is outputted as is missing. The awk below runs... (3 Replies)
Discussion started by: cmccabe
3 Replies
9. Shell Programming and Scripting
Trying to get the unique count of the below input, but if the text in beginning of $5 is a partial match to another line in the file then it is not unique.
awk
awk '!seen++ {n++} END {print n}' input
7 input
chr1 159174749 159174770 chr1:159174749-159174770 ACKR1
chr1 ... (2 Replies)
Discussion started by: cmccabe
2 Replies
10. Shell Programming and Scripting
shell : bash
os : RHEL 7.2
I have a file like below
61265388
1-11Y5C-7690
1-11Y4Q-6763
INSERT INTO emp VALUES('oramds:test.xref','CBS_01','MIGWO161265388','61265388','N',SYSDATE);
INSERT INTO emp VALUES('oramds:test.xref','COMMON','MIGWO161265388','MIG1COMMON61265388','N',SYSDATE);... (3 Replies)
Discussion started by: kraljic
3 Replies
SYSTEM(3) 1 SYSTEM(3)
system - Execute an external program and display the output
SYNOPSIS
string system (string $command, [int &$return_var])
DESCRIPTION
system(3) is just like the C version of the function in that it executes the given $command and outputs the result.
The system(3) call also tries to automatically flush the web server's output buffer after each line of output if PHP is running as a
server module.
If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru(3)
function.
PARAMETERS
o $command
- The command that will be executed.
o $return_var
- If the $return_var argument is present, then the return status of the executed command will be written to this variable.
RETURN VALUES
Returns the last line of the command output on success, and FALSE on failure.
EXAMPLES
Example #1
system(3) example
<?php
echo '<pre>';
// Outputs all the result of shellcommand "ls", and returns
// the last output line into $last_line. Stores the return value
// of the shell command in $retval.
$last_line = system('ls', $retval);
// Printing additional info
echo '
</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;
?>
NOTES
Warning
When allowing user-supplied data to be passed to this function, use escapeshellarg(3) or escapeshellcmd(3) to ensure that users can-
not trick the system into executing arbitrary commands.
Note
If a program is started with this function, in order for it to continue running in the background, the output of the program must be
redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.
Note
When safe mode is enabled, you can only execute files within the safe_mode_exec_dir. For practical reasons, it is currently not
allowed to have .. components in the path to the executable.
Warning
With safe mode enabled, the command string is escaped with escapeshellcmd(3). Thus, echo y | echo x becomes echo y | echo x.
SEE ALSO
exec(3), passthru(3), popen(3), escapeshellcmd(3), pcntl_exec(3), backtick operator.
PHP Documentation Group SYSTEM(3)