3

I read on man page, but I don't understand the purpose of bash's onecmd option. If I use the set -o onecmd command, the shell immediately exits. My expectation is for it to wait for me to enter one more command before exiting, but this does not happen.

So is this option just like the exit command?

Why does bash provide this option?

Can someone give me an example of how to properly use this option?

4

As to why, I don't know, but note that you can set the options on the command line when starting the shell, e.g. here, the inner shell does read one command and then exits

bash$ PS1='onecmd$ ' bash -t 
onecmd$ echo moi;
moi
bash$

And also that it doesn't really exit after reading one command, but reads and executes at least one full line. Here's the same with two commands:

bash$ PS1='onecmd$ ' bash -t 
onecmd$ echo moi; echo hei
moi
hei
bash$

Of course, using e.g. &&, or wrapping the whole set of commands in if true; then ... fi would also work.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.