LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-17-2012, 01:09 PM   #1
Advice Pro
Member
 
Registered: Mar 2009
Location: Virginia, US
Distribution: Ubuntu 10.10 & Debian 6.0.3,
Posts: 343

Rep: Reputation: 7
How do I write a script to execute a few commands?


Let's say I wanted to open a file and a folder.
 
Old 01-17-2012, 01:13 PM   #2
skimeer
Member
 
Registered: Jun 2007
Posts: 62
Blog Entries: 1

Rep: Reputation: 0
Quote:
Originally Posted by Advice Pro View Post
Let's say I wanted to open a file and a folder.
You can do it by placing ; in between the command eg

cd Test; cat Test.txt
 
Old 01-17-2012, 01:18 PM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,811
Blog Entries: 1

Rep: Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191
Or && if the execution of a command depends on the exit status of the previous one.
 
Old 01-17-2012, 04:01 PM   #4
Advice Pro
Member
 
Registered: Mar 2009
Location: Virginia, US
Distribution: Ubuntu 10.10 & Debian 6.0.3,
Posts: 343

Original Poster
Rep: Reputation: 7
Quote:
Originally Posted by skimeer View Post
You can do it by placing ; in between the command
Up to how many semicolons can I use?
 
Old 01-17-2012, 04:06 PM   #5
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,811
Blog Entries: 1

Rep: Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191
Quote:
Originally Posted by Advice Pro View Post
Up to how many semicolons can I use?
I'm not sure if there's any limit (I might be wrong). Just tried a line with 60 semicolons and it worked fine (ls ; ls ; .....)
 
Old 01-18-2012, 10:24 AM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
The simplest script is basically just a text file with the commands you want to run stored one-per-line. When one command exits, the next one is executed.

But there's also a whole suite of shell syntax commands that let you do much more if desired. Variables, loops, branching statements, etc.

Here's my usual list of bash resources. Read through the first two at least. The BashGuide covers all the basic concepts in an easy-to-read form, while linuxcommand is more learn-by-doing, taking you step-by-step.

http://mywiki.wooledge.org/BashGuide
http://www.linuxcommand.org/index.php
http://mywiki.wooledge.org/BashFAQ
http://mywiki.wooledge.org/BashPitfalls
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/index.html
http://www.gnu.org/software/bash/manual/bashref.html
http://wiki.bash-hackers.org/start
http://ss64.com/bash/
 
  


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
How to execute multiple commands via SSH in a script angrymachine Linux - General 4 10-12-2011 11:05 AM
Execute series of grep commands in script ? dhschryer Linux - Newbie 3 05-13-2011 11:31 AM
[SOLVED] Script which will login to particular user and execute some commands. linux_beginer Linux - Newbie 6 03-20-2011 02:06 PM
bash - how to launch a console window via script and execute commands in it? basd Programming 4 01-26-2008 09:51 PM
Run one script, but execute commands at the same time Micro420 Programming 8 07-18-2007 01:05 AM


All times are GMT -5. The time now is 08:44 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration