niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » shell
if not equal to construct?
Post new topic   Reply to topic Page 1 of 1 [8 Posts] View previous topic :: View next topic
Author Message
Rakesh Sharma
*nix forums beginner


Joined: 28 Feb 2005
Posts: 36

PostPosted: Tue Feb 15, 2005 7:28 am    Post subject: Re: if not equal to construct? Reply with quote

"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

PostPosted: Mon Feb 14, 2005 6:36 pm    Post subject: Re: if not equal to construct? Reply with quote

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

PostPosted: Mon Feb 14, 2005 6:30 pm    Post subject: Re: if not equal to construct? Reply with quote

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

PostPosted: Mon Feb 14, 2005 6:09 pm    Post subject: Re: if not equal to construct? Reply with quote

"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

PostPosted: Mon Feb 14, 2005 5:21 pm    Post subject: Re: if not equal to construct? Reply with quote

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

PostPosted: Mon Feb 14, 2005 5:19 pm    Post subject: Re: if not equal to construct? Reply with quote

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

PostPosted: Mon Feb 14, 2005 5:18 pm    Post subject: Re: if not equal to construct? Reply with quote

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

PostPosted: Mon Feb 14, 2005 4:55 pm    Post subject: if not equal to construct? Reply with 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
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [8 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 10:14 pm | All times are GMT
navigation Forum index » Programming » shell
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts doesn't recognize "!=-" (not equal to a negative value) Paul Tilles PostgreSQL 13 Tue Jul 11, 2006 5:11 pm
No new posts Variables in SP do not compare as equal when both are NULL Vincent M IBM DB2 17 Mon Jul 10, 2006 5:33 am
No new posts Equal Cost Multi Path on kernel 2.6 bolero92@yahoo.com networking 0 Wed Jul 05, 2006 9:34 am
No new posts FAQ 4.44 How do I test whether two arrays or hashes are e... PerlFAQ Server Perl 0 Sat Jun 10, 2006 1:03 am
No new posts CONSTRUCT - Python's way of Ruby's "alias_method" Ilias Lazaridis python 16 Thu Jun 08, 2006 12:28 pm

Debt Consolidation | Read Manga Online | Mortgages | Myspace Backgrounds | Problem Mortgage
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2595s ][ Queries: 20 (0.1388s) ][ GZIP on - Debug on ]