The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Special Forums > UNIX Desktop for Dummies Questions & Answers
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 03-20-2008
Lakris Lakris is offline
Registered User
 

Join Date: Oct 2007
Posts: 80
Hello, I couldn't help wonder how I would do it in bash. This one lets the user enter all arguments first, one line at a time, then operates on the arguments.

It is more verbose than it should be, only to show usage of arrays... replace "echo "executing command"..." etc with Your actual command.

Code:
#!/bin/bash
echo Enter arguments, just press enter when finished.
cnt=0
while [ true ]; do 
	echo -n "Enter argument $(($cnt+1)): "
	read x[$cnt]
	[ "${x[$cnt]}" == "" ] && break
	cnt=$(($cnt+1))
done

echo Processing $cnt arguments

cnt=0
while (($cnt < ${#x[@]}-1 ))
 do
     echo "executing command on argument $(($cnt+1)) which is: ${x[cnt++]}"
 done

#echo ${x[@]}
/Lakris
Reply With Quote