LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > AIX
User Name
Password
AIX This forum is for the discussion of IBM AIX.
eserver and other IBM related questions are also on topic.

Notices

Reply
 
Search this Thread
Old 09-26-2012, 12:15 PM   #1
sajjadshahid
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Rep: Reputation: Disabled
Detect Enter Key pressed


Hi,
On linux, I am giving the option to input info, also giving default value so that he/she can just press enter if he/she likes to keep the default value.
It works well on linux, but on aix, it gives error on if line.

echo "Input Environment [Default: $environment] :"
read environmentEntered < /dev/tty
enter=0
if [ -z $environmentEntered ]; then;environment=$environment;else;environment=$environmentEntered;fi

syntax error at line xxx : `;' unexpected

Please help,
Thanks,
 
Old 09-26-2012, 04:01 PM   #2
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,834

Rep: Reputation: 2636Reputation: 2636Reputation: 2636Reputation: 2636Reputation: 2636Reputation: 2636Reputation: 2636Reputation: 2636Reputation: 2636Reputation: 2636Reputation: 2636
Quote:
Originally Posted by sajjadshahid View Post
Hi,
On linux, I am giving the option to input info, also giving default value so that he/she can just press enter if he/she likes to keep the default value.
It works well on linux, but on aix, it gives error on if line.

echo "Input Environment [Default: $environment] :"
read environmentEntered < /dev/tty
enter=0
if [ -z $environmentEntered ]; then;environment=$environment;else;environment=$environmentEntered;fi

syntax error at line xxx : `;' unexpected
Related to your other thread...see the suggestions offered there regarding differences between ksh and bash.
 
Old 09-27-2012, 12:38 AM   #3
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 281

Rep: Reputation: 118Reputation: 118
Hi again,

Your line:
Code:
if [ -z $environmentEntered ]; then;environment=$environment;else;environment=$environmentEntered;fi
Should be rewritten as:
Code:
if [ -z $environmentEntered ]; then environment=$environment; else environment=$environmentEntered; fi
to work under ksh93, i.e. no semicolons after "then" or "else".

Ideally you should also put the $environmentEntered in the test in quotes, which will allow it to run under the default AIX ksh too, as follows:
Code:
if [ -z "$environmentEntered" ]; then environment=$environment; else environment=$environmentEntered; fi
This assumes some default value is already set in $environment; if not, it should also be quoted (which is better practice anyway).

Regards,

Clifford
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
1-key seems to be pressed Sovetryne Linux - Newbie 1 06-29-2008 08:00 AM
passwd prompts for new password only once when <enter> is pressed powah Linux - General 1 09-13-2007 06:18 AM
Which ioctl to use to get the key pressed in the key board? Sreeram B S Linux - Kernel 0 02-24-2007 02:02 AM
How can you determine if a user pressed the enter key? jimwelc Programming 3 04-04-2006 10:08 PM
is certain key pressed at the moment ?? freeborn Programming 4 11-03-2004 03:13 AM


All times are GMT -5. The time now is 03:04 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration