Home Man
Today's Posts

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Code optimization

shell scripts

👤 Login to reply

Thread Tools Search this Thread
# 8  
Old 06-14-2018
Yes. After trying and finding out myself, I noticed the subtle difference in R and N assignments between post#2 and #5 - the $ sign!
# 9  
Old 06-14-2018
Simply break the loop if ORACLE_SID got a value!
(You do not need to check the boundaries. Imagine you have 10+ items...)

 db_a db_b db_c db_g
 db_o db_e db_k db_t
PS3=$'\n'"${R}Choose database ${N}"

select ORACLE_SID in "${OPTIONS[@]}"
  [[ -n $ORACLE_SID ]] && break
  printf "${R}Invalid number!${N}\n"

#^D pressed?
[[ -n $ORACLE_SID ]] || exit

echo "HOST=$HOST"

The Following 2 Users Say Thank You to MadeInGermany For This Useful Post:
primo102 (06-14-2018), Scrutinizer (06-14-2018)
# 10  
Old 06-14-2018
You might as well consider this adaption of your original code:

cat <<-EOF

        1 - db_a
        2 - db_b
        3 - db_c
        4 - db_g
        5 - db_o
        6 - db_e
        7 - db_k
        8 - db_t

${R}Choose database $N


read NUM
export ORACLE_SID=db_$(printf "\\$(printf "%o" $((0140+NUM)))")
export HOST=${ORACLE_SID}_qa

# 11  
Old 06-14-2018
Thank you all, finally I use MadeInGermany code modification.
# 12  
Old 06-15-2018
Hi primo102...

Just an observation and slightly off topic and assumes bash.
I have no idea which OS you are using but there are now various Linux flavours that use terminal __windows__ of varying sizes.
I am assuming that you are using the standard size of 80x24, however.....
I have seen 60x21 - (the smallest I have seen), 70x23, 77x25, 80x25 and a couple of others.
Some of the default terminal windows inside certain Linux flavours will not be able to be resized on the fly, the 60x21 one was just an example, so you might have to work around those limits!
You can check yours by using stty size and this will give the figures in reverse, something like 24 80 ...
For those terminal windows that CAN be resized on the fly you can use this at the start of your script after the "shebang":
printf "%b" "\x1B[8;24;80t"

If you really want to make it pretty some of these terminal windows can even be written into the title bar:
printf "%b" "\x1B]0;Your title bar text here.\x07"

And return back to default title:
printf "%b" "\x1B]0;\x07"

Again, purely just an observation as you are using a neatly ordered selection process.
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk command optimization SkySmart Shell Programming and Scripting 15 09-14-2014 11:17 PM
awk command optimization abhi1988sri Shell Programming and Scripting 1 12-13-2012 07:17 AM
CPU optimization Gl@)!aTor Shell Programming and Scripting 4 11-28-2012 12:41 AM
Make file optimization angelinrajeesha Programming 1 02-09-2011 04:49 PM
sed optimization njaiswal Shell Programming and Scripting 1 07-16-2009 03:25 AM
AWK optimization majormark Shell Programming and Scripting 2 06-02-2009 11:10 AM
script optimization vivek.gkp Shell Programming and Scripting 3 11-06-2008 04:37 AM
compilation parameters, code optimization SaTYR Programming 5 09-04-2008 12:07 AM
Help on optimization of the script aju_kup UNIX for Dummies Questions & Answers 2 11-20-2007 01:21 AM

All times are GMT -4. The time now is 12:33 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
Show Password