Jump to content

multiple commands in one file?

Go to solution Solved by WkdPaul,

Here :

 

Option A

#!/bin/bash

# Run copy and then the application, regardless of success of the copy
cp /home/usr/dir/file /home/usr/destination/; /usr/bin/application

exit 0

 

Option B

#!/bin/bash

# Run the application only if the copy succeeded
cp /home/usr/dir/file /home/usr/destination/ && /usr/bin/application

exit 0

 

Option C

#!/bin/bash

# Run copy in the background, then runs the application, regardless of what happens to the copy
cp /home/usr/dir/file /home/usr/destination/ & /usr/bin/application

exit 0

 

ok, so i want to do the following. i want to copy a file and launch an application from double clicking 1 file.

 

at the moment i'm just making a text file, typing in the command and marking it as executable. how can i make it do what i want?

 

i'm using Linux Mint 18.3

She/Her

Phone: OnePlus Nord CE 5G | 128GB | 8GB Ram

Main Desktop: Ryzen 5 3600 | GTX 1060 6GB | 32GB Ram
Main Laptop: Acer Aspire V3-771G | Core i7 3612QM | 16GB

Link to comment
https://linustechtips.com/topic/976598-multiple-commands-in-one-file/
Share on other sites

Link to post
Share on other sites

Here :

 

Option A

#!/bin/bash

# Run copy and then the application, regardless of success of the copy
cp /home/usr/dir/file /home/usr/destination/; /usr/bin/application

exit 0

 

Option B

#!/bin/bash

# Run the application only if the copy succeeded
cp /home/usr/dir/file /home/usr/destination/ && /usr/bin/application

exit 0

 

Option C

#!/bin/bash

# Run copy in the background, then runs the application, regardless of what happens to the copy
cp /home/usr/dir/file /home/usr/destination/ & /usr/bin/application

exit 0

 

If you need help with your forum account, please use the Forum Support form !

Link to post
Share on other sites

@wkdpaul i already tried option b, i'm going to try the others now.

She/Her

Phone: OnePlus Nord CE 5G | 128GB | 8GB Ram

Main Desktop: Ryzen 5 3600 | GTX 1060 6GB | 32GB Ram
Main Laptop: Acer Aspire V3-771G | Core i7 3612QM | 16GB

Link to post
Share on other sites

  • 2 weeks later...

Those commands do different things though.   I'd go with B but get rid of the "exit 0" or at least change it to "exit $?"

 

The subtle difference is in how errors are handled.  A will run the copy to completion and run your app regardless of any error.  B runs the same but only if successful.   C backgrounds the copy and runs both in parallel.

 

exit 0 overrides any disposition from the previous steps.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×