LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Creating a script to run two commands (https://www.linuxquestions.org/questions/programming-9/creating-a-script-to-run-two-commands-192025/)

anjaan 06-10-2004 02:32 PM

Creating a script to run two commands
 
Hi all,

I would like to create a script that runs two commands. One of the command has lot of aruguments along with the command. Any help is appreciated.

Thanks in advance.

jschiwal 06-10-2004 02:36 PM

You haven't indicated what you are trying to accomplish, or even what type of script you are writing, bash, perl, python?

david_ross 06-10-2004 02:36 PM

script.sh
Code:

/path/to/command a really long set of options that go on for ever can be placed like this there is really nothing else to it
Make the file executable then run it.

anjaan 06-10-2004 02:40 PM

Sorry....in bash

===========
#!/bin/bash

command 1

command 2
============

above doesn't work

cmfarley19 06-10-2004 02:41 PM

create a file called something like script.sh

edit the file to contain the following
Code:

#!/bin/bash

command1 -lots -of -arguments
command2

Set the permissions on the file so that you have rwx.
To run the script try
Code:

$ ./script.sh

anjaan 06-10-2004 02:44 PM

those lots of arguments are running in over 3 lines...how will it differentiate between end of command 1 and start of command 2 ? Plus command one gives error on the second line..it thinks its a new command.

cmfarley19 06-10-2004 02:53 PM

The backslash '\'
Code:

#!/bin/bash

command1 -lots -of -arguments \
          -even -more -arguemtns \
          -I'm -talking -a -whole -lot -of -arguments
command2


cmfarley19 06-10-2004 02:55 PM

David Ross,
We must have posted nearly simultaneously.

Good Suggestion!!!

anjaan 06-10-2004 03:02 PM

woo hoo .. its working ... u guys are the best :)

Thanks vey much!!!

Hko 06-10-2004 03:03 PM

[QUOTE]those lots of arguments are running in over 3 lines...[quote]3 lines is not that much. To have bash confused over large command lines, - if ever - you probably need thousands (millions?) of lines!
Quote:

how will it differentiate between end of command 1 and start of command 2 ?
Just put the command on one line. Bash will know the next line is the next command!

However, if it bothers you (or your editor) to have such long lines in the script, then spread the command over several lines and finish all but the last line with a backslash ( \ ). Nothing (not even spaces or tabs) should go after the backslash.

Like this:
Code:

commandONE \
        --first-option \
        --second-option \
        --third-option \
        first_argument \
        second_argument \
        LAST_argument
commandTWO \
        --first-option \
        --second-option \
        --third-option \
        first_argument \
        second_argument \
        LAST_argument


jschiwal 06-11-2004 05:53 AM

Sorry I was a litte curt on my answer. The second sentence didn't sink in.

Goala 06-15-2004 02:51 AM

take care and don't put a space or any other character after the \


All times are GMT -5. The time now is 07:42 PM.