bash: echo followed by command on the same line ???
This is probably a dumb question considering the nature of the 'echo' command...
Code:
echo "this is a test" >/tmp/testfile ; ls -l /tmp/ Please consider this a generic question regarding the 'echo' command itself. I only use the 'ls' command to illustrate the objective --> a 2nd command on the same line following the 'echo' command. Thanks in advance for specifics on the nature of 'echo' :) |
I'm not sure if you're asking about the output or about the command line. In the first case, if you want the result of the second command inlined with the output of echo, just try the -n option. This makes echo not print a newline at the end.
|
My question back would be, what is your example not doing that you would like it to do?
As it stands I see no issue with what you have presented. |
Both are different command, and not related. It's like:-
Code:
~$ echo "this is a test" >/tmp/testfile # Pushing echo message into a file |
Whether the two commands are separated by ";" or by a newline makes absolutely no difference. They are still entirely separate commands.
|
yes you can run it on command line as well as in script
you can run this on CLI as well as in bash script.
echo "this is a test" >/tmp/testfile ; ls -l /tmp/ |
Multiple commands are combined with list operators. From the bash man page:
Quote:
|
why didn't you just try it? I did, it worked like a charm
|
Quote:
Code:
echo "this is a test" >/tmp/testfile & ls -l /tmp/ |
Code:
echo "this is a test" >/tmp/testfile & ls -l /tmp/ Code:
echo "this is a test" >/tmp/testfile ; ls -l /tmp/ & Run process in background ; Separate commands on same line With the ; the echo command should terminate before the ls command starts (I believe) Possibly more certain would be to use && to make the ls only run if the echo terminated successfully. |
Quote:
|
I think the OP somehow believes that both commands would run simultaneously (or the changes/effects would not be recognizable immediately after echo) since they are on a single line, but no it won't.
Code:
echo "this is a test" >/tmp/testfile ; ls -l /tmp/ Code:
echo "this is a test" >/tmp/testfile |
All times are GMT -5. The time now is 07:51 AM. |