checking a variables value
|
Original Message
|
Name: Aki
Date: June 18, 2003 at 03:42:27 Pacific
Subject: checking a variables valueOS: SolarisCPU/Ram: 320 |
Comment: Hi, I have got this line in one of my scripts, md5sum $( find $directory/* -type f -print )|sort -k 1,1n >/tmp/md5sum.txt.$$ I take the directory name from command line and store it in $directory. Then I perform "find" on it and then take the "md5sum" value for each file and store the sorted output in a text file. This works fine in bash but does not work in bourne shell. It caplains about the brackets. Can someone please tell me what do I need to change to get it working in bourne shell. Also, the values that get stored after the "find" command are such that they may have spaces in them. When md5sum value of such a file is taken then md5sum considers different parts of the same file as different files and complains that they do not exist. How can I modify the code to get md5sum to consider these files as single file. Or can I perform some action to check the file value first to confirm that it is a genuine file before performing md5sum on it. I also want to ignore files on which I do not have the read permission so that "find" command does not complain. Or is there a way to suppress errors in "find" and "md5sum" commands. Thanks for taking a time out to read the long post. Aki.
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: David Perry
Date: June 18, 2003 at 05:42:24 Pacific
|
Reply: (edit)try the back tick style var=`wc -l | awk '{ print $1 }'` awk by default deal with spaces as delimters so it works well in trimming leading and trailing spaces. find . -name something 2>/dev/null you can redirect stderr to /dev/null if you don't want to see the error messages.
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: Aki
Date: June 21, 2003 at 14:38:40 Pacific
|
Reply: (edit)Hi David, I understood your second solution about sending the error messages to /dev/null and this works fine but I could not understnad the first solution. What are you actually talking about when you say, ********* try the back tick style var=`wc -l | awk '{ print $1 }'` ********* I understand that "wc -l" will print the number of lines in the input so "awk '{ print $1 }' will print the same number. Can you please explain what do you actually mean here. I tried to put the back tick instead of $ sign and brackets like, md5sum `find $directory/* -type f -print` This works fine in bash but compalins in bourne shell. It says, ******** ./finddup: test: argument expected ******** How can I get this statement to work in "sh". Thanks for your time. Aki.
Report Offensive Follow Up For Removal
|
Use following form to reply to current message: