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

#!/bin/bash

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

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

fi
done
fi


See More: Unix script help!

Report •

#1
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":

#!/bin/bash

bcnt=0
for i in /dev/*
do
   # look at the first character of the object
   fchar=$(ls -l $i | cut -c1)
   if [[ "$fchar" == "b" || "$fchar" == "c" ]]
   then
      ls -l $i
      ((bcnt=bcnt+1))
   fi
done

echo $bcnt

Let me know if you have any questions.


Report •

#2
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