How to run several bash commands put in bash command line?
How to run several bash commands put in bash command line without needing and requiring a script file.
Because I'm actually a windows guy and new here so for illustration is sort of :
will do output, for example:
as it is analogous to windows:
Sincere help is really grateful to my thankfulness..
Moderator's Comments:
Please use CODE tags when displaying sample input, output, and code segments.
Last edited by Don Cragun; 01-22-2018 at 09:58 PM..
Reason: Add CODE and ICODE tags.
If you're using Bash, then the simplest way to do this is just to separate them with semi-colon (;) characters. Commands separated by semi-colons will be executed one after the other, regardless of the success or failure of the preceding command.
Example:
There are a few other ways to do this. If you only want the next command in the chain to be executed if the previous command was a success, then you can use a logical 'and' operator, represented by two ampersand (&) symbols:
And lastly, if you only want a command chain to continue if the previous command fails rather than succeeds, you can use the logical 'or' operator, represnted by a double pipe (|) symbol:
Note as you want ${PATH} to be expanded by the bash script you should protect if from being expanded by you current shell. An easy way to ensure this is to enclose the command within single quotes for example:
This User Gave Thanks to Chubler_XL For This Post:
What you originally have is more like saying "Run echo ${PATH} in the background and (ignoring if it works or not) run echo have a nice day! in the foreground"
Your output may not always be consistent. In this very simple case it probably always will be but more complex calls could have the output from either displayed first or even interleaved if you have two long running processes that output multiple lines. Can you tell us what you are trying to achieve here?
If you have a cmd1 ; cmd2 ; cmd3, these run sequentially. There is no return code checking done, it just runs one after the other.
If you have a cmd1 & cmd2 & cmd3 &, these run in the background (so disconnected from your STDIN (usually keyboard) and may independently write output to STDOUT (usually screen) ) and because cmd3 has a trailing & putting it in the background, you get dropped back to the shell (or calling program) and can carry on with other work. This may or may not be what you wanted.
If you have a mixture then you have to interpret what will happen. You can also add conditional execution, so cmd1 && cmd2 || cmd3 will run cmd1. If there is a zero return code (deemed as success) then run cmd2. If either cmd1 or cmd2 have a non-zero return code (deemed as a failure) then run cmd3
This can be quite compact but often can get complicated to interpret, so most people a re more explicit with something more like:
Does this help, or just confuse? Apologies if it is the latter.
Hi,
I downloaded source code file from The GNU website and changed the source code of ls.c file, added printf command to it. It worked fine. Then, I deleted the printf command, saved the file and ran the command 'make sudo && make install' closed the terminal and printf statement went away.
I... (1 Reply)
Hi everyone,
I want to kill process through the web, so I create html page with single bottom that run kill command in shell script with CGI.
Here is html code:
<td><form METHOD="GET" action="http://IP:port/cgi_bin/script.cgi" > <input type="submit" value= "Submit" > <INPUT name="q"... (7 Replies)
I use plink.exe to automate remote commands that return data to Windows machines. This works well on newer servers running Red Hat since the commands were developed for bash and the designated user's login shell is bash. I need to also support older servers which are running Solaris 10 but the... (5 Replies)
hello, i am facing some issue. I am using a simple bash script that via sshpass put a command into router. Now, problem is that i have a file and commands into it.
sshpass -p $pass ssh -o $log -n $user@$h /ip address set address=10.0.0.1/24
so if I have that command ip address set ... (0 Replies)
I am having trouble with bash. I am trying to put a command in an if statement and then compare it to a string.
This works perfectly.
echo $(ipcs | grep Shared | awk '{print $2}')When I put it in an if statement I get some problems.
$ if ; then echo expression evaluated... (10 Replies)
#!/bin/bash
#...
for i in `ls -c1 /usr/share/applications`
do
name="cat $i | grep ^Name= | cut -d = -f2"
echo $name
#...
done
Now inside name as output is present:
while i want only the result of the command.
Ideally i would like obtain that information using only bash ... or... (8 Replies)
Hi all. On X11 I'm on a shell ...shell_1 (/bin/bash). From here I want to open another shell window shell_2 who executes commands like "ls -l" or programs like ". /program"... so the "result" of commands shows in shell_2 window and not in shell_1. Is that possible ? (4 Replies)
Server: IBM p770
OS: AIX 6.1 TL5 SP1
When one of our develoeprs types "bash" on the command line to switch shells, it hangs. For some reason, two bash processes are created....the first bash process spawns a second bash process in the same console, causing a hang. Anyone have any idea what... (2 Replies)
Hello All. I suspect that this will be a clear noob question, but I haven't been able to figure it out using the usual methods, so I turn to you.
I've written a script to create input files for the quantum chemistry program NWCHEM. Generally you create an input file and then execute it by... (12 Replies)
hi,
i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)