What is the difference between #!/bin/sh and #!/bin/bash?
(#!/bin/bash ) What exactly is this ?
Learn X in Y minutes Where X=bash
# Built-in variables:
echo "Last program's return value: $?"
echo "Script's PID: $$"
echo "Number of arguments passed to script: $#"
echo "All arguments passed to script: $@"
echo "Script's arguments separated into different variables: $1 $2..."
pwd = print working directory
*Regex pattern = regular expression pattern
=~
operator, which tests a string against a Regex* pattern
ex: "$Email" =~ [a-z]+@[a-z]{2,}\\.(com|net|org)
# Note that =~ only works within double [[ ]] square brackets,
# which are subtly different from single [ ].
Your shell program looks through each directory separated by a : to see if the ls command exists in each of these directories. When recreating the shell, we used a function called stat to check if the ls command existed by appending /ls to each PATH directory and entering the new PATH directory into the stat function to see if the executable file exists in each directory. If it didn’t exist, we recreated an error message similar to the normal output of the shell.
If we pass in just ls
without the PATH where the command lives, our simple shell won’t work. This is why we have to have another condition that finds all the directories in the PATH variable, appends /ls
to each PATH variable, then uses stat
to check if the file exists. If it does exist, then use execve
to execute the program.