| Author |
Message |
Rakesh Sharma *nix forums beginner
Joined: 28 Feb 2005
Posts: 36
|
Posted: Tue Feb 15, 2005 7:28 am Post subject:
Re: if not equal to construct?
|
|
|
"Rob" <rob@nospam.com> wrote in message news:
| Quote: |
im so close.... ive constructed a default value for a variable thats based
on a number of previous inputs
below i want an input that displays the current value, and if the user hits
return, the value stays the same
otherwise, it takes on whatever is input. this is using bash on linux.
thanks!
printf "Enter Application branch name: [$app_branch] "
read app_branch2
if ["$app_branch2"] -ne ""
then app_branch=$app_branch2
fi
|
with the 'test' command we can do this, since no else clause is involved:
[ -n "$app_branch2" ] && app_branch=$app_branch2
Or,
if [ 'X' != "X$app_branch2" ]; then
app_branch=$app_branch2
fi
Or,
you can use the 'case' construct also:
case $app_branch2 in ?*) app_branch=$app_branch2;; esac |
|
| Back to top |
|
 |
Bill Marcum *nix forums Guru
Joined: 28 Mar 2005
Posts: 1264
|
Posted: Mon Feb 14, 2005 6:36 pm Post subject:
Re: if not equal to construct?
|
|
|
On Mon, 14 Feb 2005 19:09:24 GMT, Rob
<rob@nospam.com> wrote:
| Quote: |
thanks again chris, there's something unusual going on then. when i run the
code and hit return on the default value, it works fine. however
if i enter anything, then errors result. See how I enter "111" below:
Enter Application branch name: [wachovia_1_0_patches]111
./build.sh: line 50: [111: command not found
./stage_branch_build_wachovia_all.sh stage web4 wachovia_1_0_patches
coreserv_1_2_4_patches
You need a space after [. |
|
|
| Back to top |
|
 |
Rob *nix forums Guru Wannabe
Joined: 21 Feb 2005
Posts: 243
|
Posted: Mon Feb 14, 2005 6:30 pm Post subject:
Re: if not equal to construct?
|
|
|
nevermind, i have it working though im not sure what was wrong. perhaps a
hidden character in there somewhere |
|
| Back to top |
|
 |
Rob *nix forums Guru Wannabe
Joined: 21 Feb 2005
Posts: 243
|
Posted: Mon Feb 14, 2005 6:09 pm Post subject:
Re: if not equal to construct?
|
|
|
"Chris F.A. Johnson" <cfajohnson@gmail.com> wrote in message
news:37c8gtF5abtvnU2@individual.net...
| Quote: | On Mon, 14 Feb 2005 at 18:19 GMT, sfgroups@gmail.com wrote:
when you comparing string you have use =, !=.
if [ "$app_branch2" != "" ]
then
app_branch=$app_branch2
fi
or
if [ -z "$app_branch2" ]
That should be -n, not -z.
then
app_branch=$app_branch2
fi
--
|
thanks again chris, there's something unusual going on then. when i run the
code and hit return on the default value, it works fine. however
if i enter anything, then errors result. See how I enter "111" below:
Enter Application branch name: [wachovia_1_0_patches]111
../build.sh: line 50: [111: command not found
../stage_branch_build_wachovia_all.sh stage web4 wachovia_1_0_patches
coreserv_1_2_4_patches
It's actually trying to execute the command - note I've tried this using
your -n test as well, with the same result. Here is the code:
read -ep "Enter Application branch name: [$app_branch]" app_branch2
if ["$app_branch2" != "" ]
then echo "different"
fi
build_command="$build_script $buildname $servername $app_branch $cs_branch"
echo $build_command |
|
| Back to top |
|
 |
Chris F.A. Johnson *nix forums Guru
Joined: 20 Feb 2005
Posts: 2268
|
Posted: Mon Feb 14, 2005 5:21 pm Post subject:
Re: if not equal to construct?
|
|
|
On Mon, 14 Feb 2005 at 18:19 GMT, sfgroups@gmail.com wrote:
| Quote: |
when you comparing string you have use =, !=.
if [ "$app_branch2" != "" ]
then
app_branch=$app_branch2
fi
or
if [ -z "$app_branch2" ]
|
That should be -n, not -z.
| Quote: | then
app_branch=$app_branch2
fi
|
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
===================================================================
My code (if any) in this post is copyright 2005, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License |
|
| Back to top |
|
 |
Sun *nix forums beginner
Joined: 30 Mar 2005
Posts: 43
|
Posted: Mon Feb 14, 2005 5:19 pm Post subject:
Re: if not equal to construct?
|
|
|
when you comparing string you have use =, !=.
if [ "$app_branch2" != "" ]
then
app_branch=$app_branch2
fi
or
if [ -z "$app_branch2" ]
then
app_branch=$app_branch2
fi |
|
| Back to top |
|
 |
Chris F.A. Johnson *nix forums Guru
Joined: 20 Feb 2005
Posts: 2268
|
Posted: Mon Feb 14, 2005 5:18 pm Post subject:
Re: if not equal to construct?
|
|
|
On Mon, 14 Feb 2005 at 17:55 GMT, Rob wrote:
| Quote: | im so close.... ive constructed a default value for a variable thats based
on a number of previous inputs
below i want an input that displays the current value, and if the user hits
return, the value stays the same
otherwise, it takes on whatever is input. this is using bash on linux.
thanks!
printf "Enter Application branch name: [$app_branch] "
read app_branch2
|
With bash, you could use the readline library so that the user
can edit the line:
read -ep "Enter Application branch name: [$app_branch] " app_branch2
| Quote: | if ["$app_branch2"] -ne ""
then app_branch=$app_branch2
fi
|
Read the test man page ( "[" is a synonym for "test").
if [ -n "$app_branch2" ]
then
app_branch=$app_branch2
fi
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
===================================================================
My code (if any) in this post is copyright 2005, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License |
|
| Back to top |
|
 |
Rob *nix forums Guru Wannabe
Joined: 21 Feb 2005
Posts: 243
|
Posted: Mon Feb 14, 2005 4:55 pm Post subject:
if not equal to construct?
|
|
|
im so close.... ive constructed a default value for a variable thats based
on a number of previous inputs
below i want an input that displays the current value, and if the user hits
return, the value stays the same
otherwise, it takes on whatever is input. this is using bash on linux.
thanks!
printf "Enter Application branch name: [$app_branch] "
read app_branch2
if ["$app_branch2"] -ne ""
then app_branch=$app_branch2
fi |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|