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

Link to comment
Share on other sites

Link to post
Share on other sites

I need a better explanation of what you want.

If you want multiple commands in one script you can put them on new lines or separate with a ;

Link to comment
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 comment
Share on other sites

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 comment
Share on other sites

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

×