Evaluating command output (shell script )


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Evaluating command output (shell script )
# 1  
Old 07-07-2008
Evaluating command output (shell script )

Hello, in a script i would like to evaluate a command output with a grep, for example, to know if the parameter defined by the user is in the output.

Something like: the_command | grep $1

Please, how is the way to evalulate in this a script, like

if [ the_command evaluation (grep) ]
echo "incorrect parameter, not in the list of allowed values"
exit
fi
# 2  
Old 07-07-2008
Just a sample of what you can do...
<code>
#!/usr/bin/ksh

#Test params
if [ $# -eq 0 ];
then
echo "No params!"
echo "Usage : $0 params..."
exit 1
else
#Count the params
echo "You have $# arguments"
echo "The params are $@"

for i in "$@"
do
if [ -f $i ]; (In case of looking if its a file... )
then
echo " file $i exists"
...
else
echo "fie $i missing"
exit 1
fi
done
fi
</code>

Last edited by vbe; 07-07-2008 at 01:58 PM..
# 3  
Old 07-08-2008
Quote:
Originally Posted by vbe
Just a sample of what you can do...
<code>
#!/usr/bin/ksh

#Test params
if [ $# -eq 0 ];
then
echo "No params!"
echo "Usage : $0 params..."
exit 1
else
#Count the params
echo "You have $# arguments"
echo "The params are $@"

for i in "$@"
do
if [ -f $i ]; (In case of looking if its a file... )
then
echo " file $i exists"
...
else
echo "fie $i missing"
exit 1
fi
done
fi
</code>
Very useful, thank you very much.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pipe command output to shell script?

Hi Team, Need a help on how to pipe a command out put to a shell script. My shell script looks like below. cat shell_script #!/usr/bin/ksh input =$@ echo " we are inside the shell script" echo " here are the input parameters" .......................... .................. ... (11 Replies)
Discussion started by: gvkumar25
11 Replies

2. Shell Programming and Scripting

How to echo output of a UNIX command (like ls -l ) using shell script.?

How do i echo the output of a unix command using shell script??? Like: echo /etc/ ls -l (2 Replies)
Discussion started by: sunny2802
2 Replies

3. Shell Programming and Scripting

Shell script to replace output of command

Hi I would like to write a shell script which replace particular text in output of a shell command. For example : If I execute pwd (if dir is /users/master/) it should display as - /users/Master_directory/. Also, for generalising the script I would like to receive parameters when I run the... (3 Replies)
Discussion started by: ratneshnagori
3 Replies

4. Shell Programming and Scripting

shell script to format command output

Hello team, I am running below command which is giving following output. bash-3.00$ ps -eo pid,pcpu,args | sort +1n | grep -i java 12 0.0 grep -i java 8804 0.0 /opt/app/ccr/home/ccr/WebSphere/AppServer/java/bin/sparcv9/java -XX:+UnlockDiag 9241 0.0... (7 Replies)
Discussion started by: coolguyamy
7 Replies

5. Shell Programming and Scripting

Need help with shell script - output of top command

I have written shell script to send file as an attachemt of email and output of "top -o res" command as email body. it works fine if i execute manually from prompt but it does not send "top -o res" command output in email body when it is executed via crontab. Any suggestions. My script is below:... (5 Replies)
Discussion started by: needyourhelp10
5 Replies

6. UNIX for Dummies Questions & Answers

Passing command output as an argument to a shell script

Hi, I have a very small requirement where i need to pass command output as an argument while invoking the shell script.. I need to call like this sh testscript.sh ' ls -t Appl*and*abc* | head -n 1' This will list one file name as ana argument.. I will be using "$1" in the shell... (2 Replies)
Discussion started by: pssandeep
2 Replies

7. Shell Programming and Scripting

Process diff command output in a shell script

diff -yta file1 file2 #!/usr/abc/b/bin/perl5.6 | #!/usr/abc/b/bin/perl5.8 Notable thing about above line is "|" appears at 62nd position. When the same line is assigned in a variable in a ksh script, using ss=$(diff -yta file1 file2) it appears as ... (4 Replies)
Discussion started by: bhaliyajalpesh
4 Replies

8. UNIX for Dummies Questions & Answers

How do i tell my bash shell script to test the output of a command against something

How do i tell my bash shell script to test the output of the command i'm using?? I want this script to look for lines not equal to 1 then let me know.. $ cat blah ; echo ---- ; cat blah.sh 1 fe 1 fi 1 fo 0 fum 1 blahda 1 blah 0 blahh 1 bla 1 bl 1 blahhh ---- #!/bin/bash while... (1 Reply)
Discussion started by: phpfreak
1 Replies

9. Shell Programming and Scripting

reading command output from shell script

Hi List, How to read the output of a command executed from a script. For ex. sample_scritp.sh ------------- useradd testuser1 password testuser1 .... ..... -------------- This prompts for "password", and "confirm password", for which i need to give the values from script. Can... (4 Replies)
Discussion started by: sri b
4 Replies

10. Shell Programming and Scripting

Capturing shell script command output

I am trying to check to see if a file exists on a ftp server, well, I know that cant be done, atleast directly, So I came up with this small script ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD cd public_html/crap dir $FILE quit END_SCRIPT Where the $ variable... (2 Replies)
Discussion started by: designflaw
2 Replies
Login or Register to Ask a Question