How can I execute three commands on one command line in Linux? I tried the below:
sudo -u oracle -i ; cd /lo2/ram/daska; ./script.sh
When I execute this only the sudo
command is executing.
Please advise me
Linux allows you to enter multiple commands at one time. The only requirement is that you separate the commands with a semicolon. Running the combination of commands creates the directory and moves the file in one line.
Repeating a Command Using 'for' Loop You can use a 'for' loop to print a certain command multiple times. There are different variations of the 'for' loop, and we will explore all of them with the help of different bash scripts.
Use && separator
sudo -u oracle -i && cd /lo2/ram/daska && ./script.sh
After executing sudo
there's a new shell and the rest of "commands" are not part of it but part of the parent shell. You can do:
sudo -u oracle -i bash -c "cd /lo2/ram/daska && ./script.sh"
Or directly,
sudo -u oracle -i /lo2/ram/daska/script.sh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With