In the request script it stops at read -e:
-n Do you want to configure Cache Manager? [Y/N]
/var/tmp//installe5aOBQ/checkinstallh5aOBQ: -e: is not an identifier
pkgadd: ERROR: request script did not complete successfully
If I replace "read -e -n 1" with simple read I get
/var/tmp//install0UaOMQ/checkinstall3UaOMQ: test: argument expected
pkgadd: ERROR: request script did not complete successfully
Do you want to configure Cache Manager? [Y/N] /var/tmp//installltaiLW/checkinstallotaiLW: -sn1: is not an identifier
pkgadd: ERROR: request script did not complete successfully
Why don't the read parameters work properly ? I have same with read -e , read -n 1, etc.
bash-3.00# /bin/bash --version
GNU bash, version 3.00.16(1)-release (sparc-sun-solaris2.10)
Copyright (C) 2004 Free Software Foundation, Inc.
bash-3.00# /usr/bin/bash --version
GNU bash, version 3.00.16(1)-release (sparc-sun-solaris2.10)
Copyright (C) 2004 Free Software Foundation, Inc.
In the scripts I use #!/bin/bash
The request script I use in the package is pretty long. I refer only to this section as it is not related to nothing before.
So if I run it separate it works.
If I run it in the request script:
I have to delete read parameters -e -n 1 as they generate errors
Then I get
/var/tmp//install59a41W/checkinstall89a41W: test: argument expected
pkgadd: ERROR: request script did not complete successfully
bash-3.00# cat test.sh
#!/bin/bash
until [ -n "$CONFIGCACHE" ] && [ -n "$prompt" ] && [ -z \`echo $CONFIGCACHE | sed -e 's/[YN]//g' \` ]
do
echo -n "Do you want to configure Cache Manager? [Y/N] "
read -e -n 1 CONFIGCACHE
echo ""
prompt=1
done
bash-3.00# ./test.sh
Do you want to configure Cache Manager? [Y/N] Y
If it works when run separately, but not in the larger script then obviously the problem is related to something before.
Then it is not being run by bash!
(There is no point to using the -e option with -n1; -e enables line editing, but since you are only allowing a single character to be entered, it is not possible to edit the line.)
[color=red]Please put code inside
tags.
bash-3.00# cat test.sh
#!/bin/bash
[/quote]
[indent]
The following code is bloated and convoluted; that can make debugging difficult. Please replace it with the snippet I suggested before.
And I repeat: [b]What command line do you use to run it?
Of course that I tried your suggestion. Your code generates errors as well because of read parameters.
But you might be right about the fact that the script is not run by bash.
My "request" script is part of the packaging developed for an application. So I don't really know how it is run.
Still I read a doc that specified this about packaging scripts:
"The script is composed of Bourne shell commands.
The script's file permissions should be set to 0644.
The script does not need to contain the shell identifier (#! /bin/sh)."
So it uses /bin/sh and even if I put /bin/bash it disregards that.
If the permissions are 0644, then it isn't being treated as an executable script, but as the argument to a shell command, and it will be run by whatever shell is used on the command line, e.g., /bin/sh scriptname. (That's why I asked how it was being run.)
If you really want to allow the user to enter just one key, either have the packaging script call a wrapper that does use bash to execute the script, or use dd instead of read.
printf "Do you want to configure Cache Manager? [Y/N] "
[ -t 0 ] && { _STTY=`stty -g`; stty -icanon -echo min 1; }
while :
do
CONFIGCACHE=`dd bs=1 count=1 2>/dev/null`
case $CONFIGCACHE in
[yYnN]) break ;;
esac
done
[ -t 0 ] && stty $_STTY
echo "$CONFIGCACHE"