- Create a script file called nf that contains
instructions to count the number of files in the current directory.
You can check your answers here.
ls | wc -l
- What command do you use to make this file executable?
chmod +x nf
- What directory should you put the file in?
~/bin
- Add a comment at the begining of the file with your name and the date
# Phil Aylesworth, October 2004
ls | wc -l
- Add some text to the output to describe the number. i.e. "Files in the current directory:"
# Phil Aylesworth, October 2004
echo "Files in the current directory:"
ls | wc -l
- Modify the script so that it includes the absolute pathname of the directory.
This is stored in the variable called PWD.
# Phil Aylesworth, October 2004
echo "Files in $PWD:"
ls | wc -l
- Store your first name in a variable and then display it with a meaningful message.
name=Phil
echo "My name is $name."
- Add a comment on the same line as you set the variable.
name=Phil # This is my name
echo "My name is $name."
- At the command prompt or in a script file, create two variables with numbers stored in them.
Calculate the product (multiplication) of these and display it.
a=54
b=12
echo "The product of $a and $b is $((a*b))."
- Assign the value of this product to another variable then display that new variable.
a=54
b=12
c=$((a*b))
echo "The product of $a and $b is $c."