how to get status array for the commands in eval


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to get status array for the commands in eval
# 1  
Old 01-10-2008
how to get status array for the commands in eval

I want to get a status code array for the commands in eval.

For example,
eval "ls abc; ls def; ls $HOME"

I want to get the status code for each ls command in eval. Is there any way to make it?

Thanks.
# 2  
Old 01-10-2008
I am not sure why you would want to do this. This is hard to read and not maintainable. Why are you using eval in this case?

What exactly are you trying to accomplish and why does it have to be on one line?
# 3  
Old 01-10-2008
Quote:
Originally Posted by frank_rizzo
I am not sure why you would want to do this. This is hard to read and not maintainable. Why are you using eval in this case?

What exactly are you trying to accomplish and why does it have to be on one line?
The command list string is inputed by the user, and the script is supposed to run it.
Anyway, I found a workaround by running each command separately:

command="ls abc; ls $HOME"

while read cmd
do
cmd="sudo $cmd"
$cmd
if [[ x"${PIPESTATUS[0]}" != x"0" ]]
then
exit_code=${PIPESTATUS[0]}
fi
done << HERE
$(echo $command | awk -F';' '{for(i=1;i<=NF;i++) print $i}')
HERE
exit $exit_code

But I met a different problem when the user doesn't have a sudo privilege. I have to use su:

command="ls abc; ls $HOME"
su - -c "$command"

In this case, is there anyway I can get status code for each ls command in $command? Since su - -c "$command" will ask for root password, and I don't want the user to input the password twice.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use exit status of two commands in if statement ?

I am trying to write a shell script, which looks like #!/usr/bin/env bash #set -e RED="`tput setaf 1`" GREEN="`tput setaf 2`" BLUE="`tput setaf 4`" NORM="`tput sgr0`" pushd ${MY_GIT_TOP}/body/Ue/test >/dev/null #MY_GIT_TOP is set my by gitenv make test_trinity_svp pushd... (8 Replies)
Discussion started by: Sekhar419
8 Replies

2. UNIX for Advanced & Expert Users

FTP commands to check the file status

Hi Experts, Can some one let me know the FTP commands to check the file status i.e i want to check whether my files are locked or in open status. I am connecting FTP from local machine. Regards, Spidy (1 Reply)
Discussion started by: spidy
1 Replies

3. Shell Programming and Scripting

Error in eval eval command to print html tags

anyone has any info on why this is complaining??? vivek@vivek-c5e55ef2e ~/TAC $ zoneCounter=1 vivek@vivek-c5e55ef2e ~/TAC $ optUsage1=23% vivek@vivek-c5e55ef2e ~/TAC $ eval eval echo "<th>Zone $zoneCounter </th><th align=\"left\"> \$optUsage$zoneCounter </th>" -bash: syntax error... (13 Replies)
Discussion started by: vivek d r
13 Replies

4. Shell Programming and Scripting

Error in eval eval command to print html tags

anyone has any info on why this is complaining??? vivek@vivek-c5e55ef2e ~/TAC $ zoneCounter=1 vivek@vivek-c5e55ef2e ~/TAC $ optUsage1=23% vivek@vivek-c5e55ef2e ~/TAC $ eval eval echo "<th>Zone $zoneCounter </th><th align=\"left\"> \$optUsage$zoneCounter </th>" -bash: syntax error... (1 Reply)
Discussion started by: vivek d r
1 Replies

5. Shell Programming and Scripting

Strange result of eval, how does eval really work with ssh?

Hi all, some small script with eval turned me to crazy. my OS is linux Linux s10-1310 2.6.16.53-0.8.PTF.434477.3.TDC.0-smp #1 SMP Fri Aug 31 06:07:27 PDT 2007 x86_64 x86_64 x86_64 GNU/Linux below script works well #!/bin/bash eval ssh remotehost date eval ssh remotehost ls below... (1 Reply)
Discussion started by: summer_cherry
1 Replies

6. Shell Programming and Scripting

Using eval to populate an array in the background

Hi. I am trying to populate an array using eval in the background within a function. So this function will create a list of 3 character directories from SVN and store in an array. I want to call this function when the script starts in the background unknown to the user. The problem is that... (2 Replies)
Discussion started by: jmiaebrown
2 Replies

7. Shell Programming and Scripting

checking for return status between multiple commands

i have to run set of commands command1 command2 command3 command4 Now Whenever any of these command fails i should quit while capturing error message. Is there a better way then checking for $? after each command. (1 Reply)
Discussion started by: vickylife
1 Replies

8. Shell Programming and Scripting

eval, array, number of elements - couldn't get it

I try to get a number of elements in an array, using dynamic array name. I need the array name to be dynamic. The array name is constructed as 'inf_ln_$nmb', where $nmb is a file line number So, say I have the arr 'inf_ln_4': > for (( el=0; el<${#inf_ln_4}; el++ )); do > echo "$el:... (1 Reply)
Discussion started by: alex_5161
1 Replies

9. Shell Programming and Scripting

exit status of eval exec

I am using ksh88 and I am trying to catch the return status of opening a file using a file descriptor and the exec and eval commands. However I am not having much success. Here is what I have: eval "exec $next_fh>$1" This opens the file if the file is $1 is valid, however I want to make... (1 Reply)
Discussion started by: robotball
1 Replies

10. UNIX for Dummies Questions & Answers

Confuse on how to use array and eval..

Hi, Can anyone advise me on how to use array on Bash? I am really confuse in how eval is link to array... What i wan to do is let say i have an index of an array of 50. Store either 'N' or 'Y' or "NA" in each index. how to i go about doing it.. then lastly how to i print all the values out in... (2 Replies)
Discussion started by: Kinki
2 Replies
Login or Register to Ask a Question