Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

and then execute it as you would any other native Linux command:


Click here to view code image
matthew@seymour:~$ chmod +x myenv


This line turns on the executable permission of myenv, which can be checked
with the ls command and its -l option like this:


Click here to view code image
matthew@seymour:~$ ls -l myenv
-rwxr-xr-x 1 matthew matthew 0 2010-07-08 18:19 myenv


Running the New Shell Program


You can run your new shell program in several ways. Each method produces
the same results, which is a testament to the flexibility of using the shell with
Linux. One way to run your shell program is to execute the file myenv from
the command line as if it were a Linux command:


Click here to view code image
matthew@seymour:~$ ./myenv


A second way to execute myenv under a particular shell, such as pdksh, is
as follows:


Click here to view code image
matthew@seymour:~$ pdksh myenv


This invokes a new pdksh shell and passes the filename myenv as a
parameter to execute the file. A third way requires you to create a directory
named bin in your home directory and to then copy the new shell program
into this directory. You can then run the program without the need to specify a
specific location or to use a shell. You do so like this:


Click here to view code image
matthew@seymour:~$ mkdir bin
matthew@seymour:~$ mv myenv bin
matthew@seymour:~$ myenv


This works because Ubuntu is set up by default to include the executable path
$HOME/bin in your shell’s environment. You can view this environment
variable, named PATH, by piping the output of the env command through
fgrep, like so:


Click here to view code image
matthew@seymour:~$ env | fgrep PATH
/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin: \

Free download pdf