Unix script help!

December 6, 2011 at 06:03:26
Specs: windows 7
I want to make the following script:

Write script, which can accept two arguments from the command line. The arguments will be integers and the first argument is smaller than the second. If the condition does not apply script will terminate with an appropriate message and exit code 1.
If the condition is true, then the program will print on screen the names and number of
special registers block (block special files), which are located in / dev if number is greater than or equal to the first argument and less than or equal to the second argument. Otherwise, and terminates the execution with an appropriate message and exit code 2.

After the "exit 1" i dont know exactly how to continue the script,so i think that the following lines are wrong!I am confused


if [ $1 -gt $2 ];then
echo "wrong'
exit 1

if [ $1 -lt $2 ];then

for i in /dev;do

if [ \($(wc -l) -le $1\ ] -a [ \($(wc -l) -ge $2\];then

ls -l
ls -l|wc -l


See More: Unix script help!

Report •

December 6, 2011 at 09:55:31
I am not understanding your logic with the for loop. I would expect you want to check the first character of a long listing and only display and count objects that start with "b" or "c":


for i in /dev/*
   # look at the first character of the object
   fchar=$(ls -l $i | cut -c1)
   if [[ "$fchar" == "b" || "$fchar" == "c" ]]
      ls -l $i

echo $bcnt

Let me know if you have any questions.

Report •

December 6, 2011 at 10:26:12
I am using "for" to select all files from" /dev" and then i use "if" to count the files in /dev and see if it is bigger or equal from $1 or smaller or equal from $2!
I forgot to mention that i am new in making scripts!

Report •
Related Solutions

Ask Question