LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-10-2004, 02:32 PM   #1
anjaan
LQ Newbie
 
Registered: Aug 2003
Posts: 19

Rep: Reputation: 0
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.
 
Old 06-10-2004, 02:36 PM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
You haven't indicated what you are trying to accomplish, or even what type of script you are writing, bash, perl, python?
 
Old 06-10-2004, 02:36 PM   #3
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
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.
 
Old 06-10-2004, 02:40 PM   #4
anjaan
LQ Newbie
 
Registered: Aug 2003
Posts: 19

Original Poster
Rep: Reputation: 0
Sorry....in bash

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

command 1

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

above doesn't work
 
Old 06-10-2004, 02:41 PM   #5
cmfarley19
Member
 
Registered: Nov 2002
Location: Central VA
Distribution: Ubuntu/Debian
Posts: 228

Rep: Reputation: 32
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
 
Old 06-10-2004, 02:44 PM   #6
anjaan
LQ Newbie
 
Registered: Aug 2003
Posts: 19

Original Poster
Rep: Reputation: 0
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.

Last edited by anjaan; 06-10-2004 at 02:50 PM.
 
Old 06-10-2004, 02:53 PM   #7
cmfarley19
Member
 
Registered: Nov 2002
Location: Central VA
Distribution: Ubuntu/Debian
Posts: 228

Rep: Reputation: 32
The backslash '\'
Code:
#!/bin/bash

command1 -lots -of -arguments \
          -even -more -arguemtns \
          -I'm -talking -a -whole -lot -of -arguments
command2
 
Old 06-10-2004, 02:55 PM   #8
cmfarley19
Member
 
Registered: Nov 2002
Location: Central VA
Distribution: Ubuntu/Debian
Posts: 228

Rep: Reputation: 32
David Ross,
We must have posted nearly simultaneously.

Good Suggestion!!!
 
Old 06-10-2004, 03:02 PM   #9
anjaan
LQ Newbie
 
Registered: Aug 2003
Posts: 19

Original Poster
Rep: Reputation: 0
woo hoo .. its working ... u guys are the best

Thanks vey much!!!
 
Old 06-10-2004, 03:03 PM   #10
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
[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
 
Old 06-11-2004, 05:53 AM   #11
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
Sorry I was a litte curt on my answer. The second sentence didn't sink in.
 
Old 06-15-2004, 02:51 AM   #12
Goala
Member
 
Registered: May 2004
Location: Merida (Spain)
Distribution: Debian
Posts: 89

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help to create a script to open a terminal and run commands in it. Brian1 Linux - Software 6 02-07-2005 06:46 PM
Creating a shell script to run Java program paultaylor Programming 7 11-12-2004 03:11 PM
Script to Run the Same Commands on a List of Files Chryzmo Programming 1 10-03-2004 08:34 AM
on Network Up Script run? On Battery power run script? v2-ncl Linux - General 0 12-08-2003 09:34 AM
run 2 commands in a script ddpicard Linux - General 10 06-13-2003 04:50 PM


All times are GMT -5. The time now is 01:33 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration