LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How do I write a script to execute a few commands? (https://www.linuxquestions.org/questions/linux-newbie-8/how-do-i-write-a-script-to-execute-a-few-commands-924269/)

LAPIII 01-17-2012 12:09 PM

How do I write a script to execute a few commands?
 
Let's say I wanted to open a file and a folder.

skimeer 01-17-2012 12:13 PM

Quote:

Originally Posted by Advice Pro (Post 4577069)
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

sycamorex 01-17-2012 12:18 PM

Or && if the execution of a command depends on the exit status of the previous one.

LAPIII 01-17-2012 03:01 PM

Quote:

Originally Posted by skimeer (Post 4577075)
You can do it by placing ; in between the command

Up to how many semicolons can I use?

sycamorex 01-17-2012 03:06 PM

Quote:

Originally Posted by Advice Pro (Post 4577213)
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 ; .....)

David the H. 01-18-2012 09:24 AM

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/


All times are GMT -5. The time now is 02:24 AM.