how do you compare comandline arguments in bash example i have 5 or more arguments and 2 of the arguments are the same how can do it any suggestions? my problem is that i need to compare 2 or more arguments if any of the arguments are the same sleep for 1 sec
anjoz -9 Light Poster
Recommended Answers
Jump to PostMay be there is an easier way, but here is what I can think of..
total_params=`echo $* | sed 's/ */\n/g' | sort | sed '/^$/d' | wc -l` unique_params=`echo $* | sed 's/ */\n/g' | sort -u | sed '/^$/d' | wc -l` [ $total_params -ne …
Jump to PostTo add to what thekashyap provided, you already have the count of arguments in the
$#
variable and, in bash at least, you do not need to worry about multiple spaces so you can get away without bothsed
calls.
For instance:[ $# -ne `echo …
All 6 Replies
thekashyap 193 Practically a Posting Shark
L7Sqr 227 Practically a Master Poster
thekashyap 193 Practically a Posting Shark
L7Sqr 227 Practically a Master Poster
anjoz -9 Light Poster
thekashyap 193 Practically a Posting Shark
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.