Off-Topic > Off-Topic - Tiny Tux's Corner

requesting suggestions for script (solved)

<< < (2/3) > >>

vinnie:
In both cases, the script works by specifying a single argument, I can not use more arguments simultaneously:

gclark suggestion http://nopaste.info/b26b4ba75d.html
rich suggestion http://nopaste.info/15deeb263c.html

In my (first post) version work only first ad last argouments ! (The reason is that $# assumes the value of the total number of arguments, then the others do not work)


Perhaps I have not explained well (seen as I translate):
I'd need a way to put the arguments in any order, so that all work regardless of their position, there will be some standard method?

gerald_clark:
while [ "$1" != "" ] ; do
    case $1 in
        first_string ) command;
                      shift ;;
        second_string ) command2;
                      shift;;
        * ) echo "Unknown option $1"; exit ;;
   esac
done

Rich:
Hi vinnie
You used:

--- Code: ---for i in $@
 do
 case $1 in
 n)
 sed -i 's/^.*tile_window_width.*$/tile_window_width    = 1024/' /usr/local/share/crawl/settings/tiles_options.txt &&
 sed -i 's/^.*tile_window_height.*$/tile_window_height    = 600/' /usr/local/share/crawl/settings/tiles_options.txt &&
--- End code ---
It should be:

--- Code: ---for i in $@
 do
 case $i in
 n)
 sed -i 's/^.*tile_window_width.*$/tile_window_width    = 1024/' /usr/local/share/crawl/settings/tiles_options.txt &&
 sed -i 's/^.*tile_window_height.*$/tile_window_height    = 600/' /usr/local/share/crawl/settings/tiles_options.txt &&
--- End code ---

vinnie:
gclark second suggestion http://nopaste.info/fc5a232f4d.html do infinite loop! it is dangerous  :P

rich second suggestion http://nopaste.info/a55e4e03fa.html seems to work flawlessly!

Thanks to both :)

gerald_clark:
It is not an infinite loop. The shift removes the option, leaving the rest for the next loop.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version