Hi i would like to write a "script" which takes a directory as an argument and the script will output the content of a file in this directory.Here is my code
#!/bin/sh
#set an argument to be a specified path
$1=/home/tuan/Desktop/Shell_programming/directory
#check if an argument is a directory
if [ ! -d $1 ]
then
for number in $1
do
echo "$number"
done<list
else
echo "No such that directory "
fi
After that in terminal I did:
tuan@tuan:~/Desktop/Shell_programming$ ./A3 directory
./A3: 2: directory=/home/tuan/Desktop/Shell_programming/directory: not found
No such that directory
tuan@tuan:~/Desktop/Shell_programming$
It seems there are mistakes. Can anyone point it out for me.
PS: In "directory" directory, I did created a file named "list" like below
Try to use something else than "$1" as the variable name... e.g.
#!/bin/sh
#set an argument to be a specified path
a=/home/tuan/Desktop/Shell_programming/directory
#check if an argument is a directory
if [ -d $a ]
then
for number in $a
do
echo "$number"
done
else
echo "No such that directory "
fi
#!/bin/sh
#set an argument to be a specified path
a=/home/tuan/Desktop/Shell_programming/directory/list
#check if an argument is a directory
if [ ! -d $a ]
then
for number in $a
do
echo "$number"
done
else
echo "No such that directory "
fi