-1

The question is somewhat related to the question asked here, https://stackoverflow.com/questions/5130847/shell-multiple-commands-in-one-line, but the difference is, I need to execute the whole commands whether or not the commands are successful or not. So I presume, && is not an option right? Can I use ; separated commands and eval or bash; something like

eval cd /home/user/homedir ; /home/user/homedir/sbin/daemon.sh --config /home/user/homedir/etc/dd2 --script /home/user/homedir/sbin/dd3 start action1

or something like that?

Please advise,

1
  • Is /home/user/homedir/sbin/daemon.sh --config /home/user/homedir/etc/dd2 --script /home/user/homedir/sbin/dd3 start action1 all one command? What can you tell us about what /home/user/homedir/sbin/daemon.sh does? (Also, why do you want to cd to /home/user/homedir and then use full pathnames?) Dec 21, 2012 at 17:54

2 Answers 2

0

';' works. You could also use '&', simplified like this:

/home/user/homedir/sbin/daemon.sh --config & /home/user/homedir/etc/dd2 --script & /home/user/homedir/sbin/dd3 start action1

(Simultaneous execution, see comment for clarification below)

5
  • 1
    That would run the two commands simultaneously in separate processes. (1) This doesn't sound like what was asked for. (2) This almost never makes sense when the first command is a cd, because it means that the second command won't get the benefit of the cd; i.e., it will run in whatever directory the user (the shell) is in when the command is typed, and not in /home/user/homedir, as seems to be intended. Dec 21, 2012 at 4:55
  • For simultaneous execution, then: cd /home/user/homedir; /home/user/homedir/sbin/daemon.sh --config & cd /home/user/homedir; /home/user/homedir/etc/dd2 --script & cd /home/user/homedir; /home/user/homedir/sbin/dd3 start action1 Dec 21, 2012 at 4:59
  • yup, Scott is correct. As Sectio Aurea pointed out we should use the multiple cd to execute the scripts simultaneously. Dec 21, 2012 at 5:06
  • Somebody is confused. The question gives the appearance that ~/sbin/daemon.sh ––config ~/etc/dd2 ––script ~/sbin/dd3 start action1 is one command. I asked the OP for confirmation and got no indication to the contrary. But the above answer has taken this command and broken it into three parts. This is not an answer to this question, as stated. Neither grep; Scott; /etc/passwd nor grep& Scott& /etc/passwd& will display my user ID information. Jan 5, 2013 at 0:36
  • You're right technically. It's possible that it's one command but didn't seem at all likely - looking more like a naive use of bash. I answered based on that hunch about the 'real question' and expected the OP to correct me if that wasn't useful. Jan 9, 2013 at 0:05
0

What you have is fine, except I would leave off the eval unless you have some reason for having it (I don't see any reason).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .