Results 1 to 4 of 4
new to linux and I'm trying to write a script where I have a while loop checking each argument but I can't use the shift option or else all those ...
- 11-20-2010 #1Just Joined!
- Join Date
- Nov 2010
- Posts
- 1
Noob variable question
new to linux and I'm trying to write a script where I have a while loop checking each argument but I can't use the shift option or else all those arguments go out the door for later use. So I'm trying to describe in my if statement the different variables. Basically what I'm trying to do is something like this variable:
$($args)
where $args = $# and is in a while loop that slowly counts down as it loops. The problem is I'm getting errors and I'm not sure if thats the proper format. The whole code looks like this:
Thanks in advance.Code:args="$#" while [ "args != "0"] do if [ -d "$($args)" ] then x="0" else echo -e "usage: bla bla" fi args=`expr $args - 1` doneLast edited by jamie1414; 11-20-2010 at 07:09 PM.
- 11-21-2010 #2
So you want the CLI argument array; maybe something like this?
Short and simple:Code:#!/bin/bash ## declare -i how_many=$# args=("$@") # CLI Argument Array while [ $how_many != 0 ] do if [ -d ${args[$how_many]} ] then x="0" # echo $how_many how_many=$how_many-1 else echo -e "usage: bla bla" fi # args=`expr $args - 1` done exit 0
Code:#!/bin/sh for i in $@; do echo $i done
Last edited by barriehie; 11-21-2010 at 09:03 PM.
- 11-22-2010 #3Just Joined!
- Join Date
- Nov 2010
- Posts
- 5
is bash the same linux to linux
Hi,
Newbie to bash.
Would a generic bash script work the same on SuSe as it would on Ubuntu?
Pardon me, if that is a goofy question.
By generic, I just mean like a 'hello world' and I guess I'm asking if, fundamentally,
bash works on all Linux flavours.
Thank you.
- 11-23-2010 #4


Reply With Quote
