LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 12:09 PM   #1
LAPIII
Member
 
Registered: Mar 2009
Location: Virginia, US
Distribution: Ubuntu 10.10 & Debian 6.0.3,
Posts: 350

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, 12: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, 12:18 PM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

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

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, 03:06 PM   #5
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
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, 09:24 AM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:12 PM.

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
Open Source Consulting | Domain Registration