Solaris "read -e"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Solaris "read -e"
# 8  
Old 04-02-2009
Quote:
Originally Posted by potro
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.

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 it works when run separately, but not in the larger script then obviously the problem is related to something before.
Quote:

If I run it in the request script:
1. I have to delete read parameters -e -n 1 as they generate errors

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.)
Quote:

2. Then I get
/var/tmp//install59a41W/checkinstall89a41W: test: argument expected
pkgadd: ERROR: request script did not complete successfully


Please put code inside [code] tags.
Quote:
Code:
bash-3.00# cat test.sh
#!/bin/bash


The following code is bloated and convoluted; that can make debugging difficult. Please replace it with the snippet I suggested before.
Quote:
Code:
        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

bash-3.00#


And I repeat: What command line do you use to run it?

Last edited by cfajohnson; 04-02-2009 at 07:11 AM..
# 9  
Old 04-02-2009
Hi,

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.

Bianca
# 10  
Old 04-02-2009
Quote:
Originally Posted by potro
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.

Code:
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"

# 11  
Old 04-02-2009
Thanks for the solution.

But still how could I fix the read problem, as I read a lot of parameters like this:

Code:
   
APPLOGDIR1="${DIR}/log"
echo "Please type the XAC Log Directory: (current value: $APPLOGDIR1)"
read APPLOGDIR1

If the user hits ENTER here the value of APPLOGDIR1 is set to "".

I Linux I have a function that solves that but doesn't work on Solaris:

Code:
readDefault()
{
    ARGS=""
    N=1
    LOCALBUF=""
    until  [ $N -eq $# ]
    do
        eval ARG=\${$N}
        ARGS=" $ARGS $ARG"
        N=`expr $N + 1`
    done
    read $ARGS LOCALBUF
    if [ -n "$LOCALBUF" ]
    then
        VARNAME=${!#}
        export $VARNAME=$LOCALBUF
    else
        echo "Using current value."
    fi
}

And I call it like this

Code:
echo "Please type the path of the Log directory: (current value: $SB_LOGDIR1)"
readDefault -e SB_LOGDIR1

But I didn't managed to make it work on Solaris.

Bianca
# 12  
Old 04-02-2009
Quote:
Originally Posted by potro
Code:
echo "Please type the path of the Log directory: (current value: $SB_LOGDIR1)"
readDefault -e SB_LOGDIR1

But I didn't managed to make it work on Solaris.

If you use the -e option, you must run the script with bash. No other shell has it.
# 13  
Old 04-02-2009
I removed the -e parameter. Still .. If I hit ENTER the variable maintains the it initial value, if I enter a new value it generates errors:

Code:
bash-3.00# ./test1.sh
Please type the Log Directory: (current value: /app/)
sss
./test1.sh: bad substitution
bash-3.00#

Quote:
Originally Posted by cfajohnson

If you use the -e option, you must run the script with bash. No other shell has it.
# 14  
Old 04-02-2009

This is bash only:

Code:
VARNAME=${!#}

You have bash on your Solaris box, so why not use it?

This is POSIX, but doesn't work in Bourne shell:

Code:
export $VARNAME=$LOCALBUF

.....

I hope you don't use this on your Linux box:

Code:
N=`expr $N + 1`

Bash (like all POSIX shells) has arithmetic built in:

Code:
N=$(( $N + 1 ))


Last edited by cfajohnson; 04-02-2009 at 08:52 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Solaris

Printer configuration Migration from Solaris 10 "LP" to Solaris 11 "CUPS"

Need to find a way to import an LP printers.conf file to CUPS. I have some new Solaris 11.1 boxes that need to have 300 printers added. (0 Replies)
Discussion started by: os2mac
0 Replies

5. Shell Programming and Scripting

Read from "list1" and list matches in "list2"

I want to print any matching IP addresse in List1 with List 2; List 1 List of IP addresses; 161.85.58.210 250.57.15.129 217.23.162.249 74.76.129.101 30.221.177.237 3.147.200.59 170.58.142.64 127.65.109.33 150.167.242.146 223.3.20.186 25.181.180.99 2.55.199.32 (3 Replies)
Discussion started by: lewk
3 Replies

6. Shell Programming and Scripting

Purpose of "read" and "$END$" in ksh ?

Hi, Could anyone please shed some light on the following script lines and what is it doing as it was written by an ex-administrator? cat $AMS/version|read a b verno d DBVer=$(/usr/bin/printf "%7s" $verno) I checked that the cat $AMS/version command returns following output: ... (10 Replies)
Discussion started by: dbadmin100
10 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Solaris

Solaris escape my script from "-" to "/226"

Hello everyone. I beg your guys pardon please. I try to ls -al in many path/directories. So, I put the code in text file which look like below; ls -al / ls -al /etc ls -al /etc/default ... however, when I paste it to Solaris over SecureCRT, it seems the code was escaped from "-" to... (0 Replies)
Discussion started by: Smith
0 Replies

9. Shell Programming and Scripting

read -p "prompt text" foo say "read: bad option(s)" in Bourne-Shell

Hallo, i need a Prompting read in my script: read -p "Enter your command: " command But i always get this Error: -p: is not an identifier When I run these in c-shell i get this error /usr/bin/read: read: bad option(s) How can I use a Prompt in the read command? (9 Replies)
Discussion started by: wiseguy
9 Replies

10. Shell Programming and Scripting

how to request a "read" or "delivered" receipt for mails

Dears, I've written a script which allows me to send mails in different formats with different attaches. Now I still want to add a feature to this script. My users would like to be able to receive a "read" or "delivered" receipt for their mails. The script send mails on behalve of an specific... (1 Reply)
Discussion started by: plelie2
1 Replies
Login or Register to Ask a Question