LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   AIX (https://www.linuxquestions.org/questions/aix-43/)
-   -   Detect Enter Key pressed (https://www.linuxquestions.org/questions/aix-43/detect-enter-key-pressed-4175429145/)

sajjadshahid 09-26-2012 12:15 PM

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,

TB0ne 09-26-2012 04:01 PM

Quote:

Originally Posted by sajjadshahid (Post 4789941)
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.

cliffordw 09-27-2012 12:38 AM

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


All times are GMT -5. The time now is 12:48 AM.