Presentation is loading. Please wait.

Presentation is loading. Please wait.

Executable scripts. So far We have made scripts echo hello #for example And called it hello.sh Run it as sh hello.sh This only works from current directory?

Similar presentations


Presentation on theme: "Executable scripts. So far We have made scripts echo hello #for example And called it hello.sh Run it as sh hello.sh This only works from current directory?"— Presentation transcript:

1 Executable scripts

2 So far We have made scripts echo hello #for example And called it hello.sh Run it as sh hello.sh This only works from current directory? We can do todays lecture in the lab!!!

3 overview Use the file command (before and after) Add #! to the start of shell script. THIS IS NOT A COMMENT!!! Change the permissions Add it to the path (front/end/twice). (and export it) Which, type commands What if two script paths.

4 Choosing a shell #! /bin/ksh Specifies the Korn shell #! /bin/bash Is the Bash shell #! bin/perl Forces the shell to execute perl #! /bin/awk –f I think you know this one

5 Where to put scripts Make a dir /bin or /scripts in your home dir Put a script there (mv command). File hello.sh #will says it’s a text file Add #! /bin/bash as the first line File hello.sh #will say it’s a bash script

6 File with pdf and ps [zlizjw1@unnc-cslinux ~]$ file canonical.pdf canonical.pdf: PDF document, version 1.4 [zlizjw1@unnc-cslinux ~]$ file canonical.ps canonical.ps: PostScript document text conforming at level 3.0 [zlizjw1@unnc-cslinux ~]$

7 Change permissions How do we find permissions? What is the error if we try to execute it? chmod 7XX (make it executable) Now check permissions We can now run it without “sh” or “bash” Sh hello.sh Now we can run it directly as hello.sh # JUST LIKE ANY OTHER COMMAND

8 Change PATH variable echo $PATH /usr/kerberos/bin:/bin:/usr/bin: What is the field separator??? This tells the system where to look for executable files. Add /scripts to end PATH=“$PATH:~/scripts” echo $PATH # to make sure!

9 Which script $ scripts/hello.sh hello from the scripts dir $ scripts2/hello.sh hello from the SECOND scripts dir $ hello.sh hello from the scripts dir echo $PATH /usr/kerberos/bin:~/scripts

10 Can still run 2 nd script I can still run the other script but I must refer to it expliclty. ~/scripts2/hello.sh hello from the SECOND scripts dir THE MESSAGE IS ; you should not add your /bin or /script to the start of the PATH variable, because your files will dominate!

11 Change PATH variable permanently Need to add it to one of your dot login files export PATH (makes available to subshells) ls.*bash* # to list file To run the file Either log out and log back in Or source (filename)

12 source or. [zlizjw1@unnc-cslinux ~]$ source.bash_profile hello John, you have just run.bash_profile [zlizjw1@unnc-cslinux ~]$..bash_profile hello John, you have just run.bash_profile [zlizjw1@unnc-cslinux ~]$

13 Stdin stdout Important – if you write to and from standard in and out (i.e. keyboard and screen) Then you can be used in pipelines and redirected more flexibly.


Download ppt "Executable scripts. So far We have made scripts echo hello #for example And called it hello.sh Run it as sh hello.sh This only works from current directory?"

Similar presentations


Ads by Google