# Shell Scripting Newbie

**URL:** <https://community.unix.com/t/shell-scripting-newbie/292284>\
**Category:** Shell Programming and Scripting\
**Created:** [July 26, 2011, 3:29pm UTC](https://community.unix.com/t/shell-scripting-newbie/292284 "2011-07-26T15:29:07Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![chaits84](https://community.unix.com/letter_avatar/chaits84/32/6_449c533f586939b6e5f246632a46421f.png) [@chaits84](https://community.unix.com/u/chaits84)\
**Post date:** [July 26, 2011, 3:29pm UTC](https://community.unix.com/t/shell-scripting-newbie/292284/1 "2011-07-26T15:29:07Z")

</div>

Hi Guys, I want to create a shell script to run multiple jobs in sequence.

Explaination -  
If I were to run each jobs individually I would have gone to folder - "abin"(where my shellscript is place) as follows  
cd abin  
abin \> runappeng.sh abc001  
Now, I have list of programs which are like abc001 thru abc010.  
So, my requirement is how to run the script to do this. Waht should I name it, so that when I go to abin folder and put scipt name as testmul.sh. It will intiate the sequence of programs getting executed  
and their status on the front end.

-Rgds,  
Chaits

---

<div class="post-metadata">

**Author:** ![Shell\_Life](https://community.unix.com/user_avatar/community.unix.com/shell_life/32/521_2.png) [@Shell\_Life](https://community.unix.com/u/Shell_Life)\
**Post date:** [July 26, 2011, 3:33pm UTC](https://community.unix.com/t/shell-scripting-newbie/292284/2 "2011-07-26T15:33:55Z")

</div>

Can't you just create a file:

```nohighlight
runappeng.sh abc001
runappeng.sh abc002
...
runappeng.sh abc010

```

and run it?

---

<div class="post-metadata">

**Author:** ![Nitrodist](https://community.unix.com/user_avatar/community.unix.com/nitrodist/32/7168_2.png) [@Nitrodist](https://community.unix.com/u/Nitrodist)\
**Post date:** [July 26, 2011, 3:50pm UTC](https://community.unix.com/t/shell-scripting-newbie/292284/3 "2011-07-26T15:50:39Z")

</div>

As to the status, the variable `$?` contains the return code of the previous command, so you could put after each line `echo "abc001 finished with a return code of $?"`

---

<div class="post-metadata">

**Author:** ![chaits84](https://community.unix.com/letter_avatar/chaits84/32/6_449c533f586939b6e5f246632a46421f.png) [@chaits84](https://community.unix.com/u/chaits84)\
**Post date:** [July 26, 2011, 3:54pm UTC](https://community.unix.com/t/shell-scripting-newbie/292284/4 "2011-07-26T15:54:00Z")

</div>

Sorry, abt asking such a simple question....but I seriously dont know how to do that. New kid on the block.

Step I did -  
I prepared a file with  
name as "test1.sh". Inside that file scripts were as follows -  
runappeng.sh abc001  
runappeng.sh abc002  
runappeng.sh abc003.

Now when I went to Home/abin \> test1.sh  
It thrown error -  
ksh: Test1.sh: cannot execute

So, I am not sure where I am going wrong or what I am missing.

---

<div class="post-metadata">

**Author:** ![Shell\_Life](https://community.unix.com/user_avatar/community.unix.com/shell_life/32/521_2.png) [@Shell\_Life](https://community.unix.com/u/Shell_Life)\
**Post date:** [July 26, 2011, 4:03pm UTC](https://community.unix.com/t/shell-scripting-newbie/292284/5 "2011-07-26T16:03:12Z")

</div>

```nohighlight
chmod 777 test1.sh

```

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_449c533f586939b6e5f246632a46421f.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [July 26, 2011, 4:13pm UTC](https://community.unix.com/t/shell-scripting-newbie/292284/6 "2011-07-26T16:13:39Z")

</div>

> [@](#):
>
> Now when I went to Home/abin \> test1.sh  
> It thrown error -  
> ksh: Test1.sh: cannot execute

That can't be what you actually typed. What did you type?

---------- Post updated at 02:13 PM ---------- Previous update was at 02:12 PM ----------

> [@shell\_life](#):
>
> ```plaintext
> chmod 777 test1.sh
> 
> ```

777 is not the magic sledgehammer to solve all permission problems. These numbers mean things, and 777 has further implications than you realize.

777 allows anything at all to modify the file! How about 770, or 750.

---

<div class="post-metadata">

**Author:** ![Nitrodist](https://community.unix.com/user_avatar/community.unix.com/nitrodist/32/7168_2.png) [@Nitrodist](https://community.unix.com/u/Nitrodist)\
**Post date:** [July 26, 2011, 4:21pm UTC](https://community.unix.com/t/shell-scripting-newbie/292284/7 "2011-07-26T16:21:11Z")

</div>

Corona688, sure it could if it's like

```plaintext
Home/abin > test1.sh
ksh: Test1.sh: cannot execute

```

and he has his current directory in his PATH.

Chaits, as shell\_life indicates, your file permissions does not let you to execute that file. if you do a `ls -l yourfile` you can see the permissions at the beginning of the line, something like `-rwxrwxrwx` . The gist of it is that there are 3 sets of permissions -- owner, group and other ('other' is anyone who isn't the owner or in the group). There are 3 options available -- (r)ead, (w)rite and e(x)ecute -- rwx. In order for you to run a file, it must be executable, e.g., the x flag must be set for whatever level of permission you have (if you're the owner, in the group or neither). 777 means rwxrwxrwx, which is the most permissive permission.

You use `chmod` to modify the access permissions on the file. We use numbers (aka, 777) to represent these flags. the 'r' is worth 4, the 'w' is worth 2 and the x is worth '1'. So, 4 + 2 + 1 = 7, and three sevens in a row means read, write, execute for owner, group and other. If you had permissions of 754, the owner would have read, write, execute, the group would have read and execute and other people would only have read.

You can look at [this tutorial](http://www.dartmouth.edu/~rc/help/faq/permissions.html) for more details on it.

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_449c533f586939b6e5f246632a46421f.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [July 26, 2011, 5:09pm UTC](https://community.unix.com/t/shell-scripting-newbie/292284/8 "2011-07-26T17:09:16Z")

</div>

> [@nitrodist](#):
>
> Corona688, sure it could if it's like
> 
> ```plaintext
> Home/abin > test1.sh
> ksh: Test1.sh: cannot execute
> 
> ```

No it wouldn't, since that attempts to write to test2.sh, not execute it.

---

<div class="post-metadata">

**Author:** ![Nitrodist](https://community.unix.com/user_avatar/community.unix.com/nitrodist/32/7168_2.png) [@Nitrodist](https://community.unix.com/u/Nitrodist)\
**Post date:** [July 26, 2011, 5:25pm UTC](https://community.unix.com/t/shell-scripting-newbie/292284/9 "2011-07-26T17:25:28Z")

</div>

'Home/abin \> ' being PS1 and PS2, I mean.
