Bash function problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash function problem
# 1  
Old 11-17-2016
Bash function problem

I am trying to figure out why I am having a "problem" with some functions in a bash script I am running. The reason for air quoting is that the functions are working, they are just not displaying anything to screen when called from another function. Here's an example:

Code:
function Create_Input
{
read -p "Enter customer name: " CUSTOMER
read -p "Are you including SST data? <Y/N> " SST_DATA

case $SST_DATA in
  [yY]) make_sst_data
      ;;
  [nN]) make_no_sst_data
     ;;
  *) bomb
    ;;
esac
}

In the two "make" functions, I call a spinner and I run some additional commands, but none of the output goes to screen until at the last second when everything completes (I have a sleep to pause so I can see anything that would be missed by just exiting back), then I can see it ran things. The script is going to be used by others and I put in visual queues for people to see that things are running (like the spinner as it processes files), but none of those references are coming through. The case statement itself is inside of a function that does some validations first and prompts the user for some required inputs.



Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 11-17-2016 at 12:54 PM.. Reason: Changed ICODE to CODE tags.
# 2  
Old 11-17-2016
I can't see anything in that function that could explain the behaviour you describe, so I guess the reason - if any - is up- or downstream. Run the entire script with the -x option set.
# 3  
Old 11-17-2016
Thanks Rudi, I had already tried that before posting. It all runs correctly, weird thing is, that the output is being delayed to screen until the commands all complete and then they all pop up. Was hoping I was just having a brain fart and forgetting to declare something globally within the script that I should have and didn't, although everything is internal to the script.


(To the moderator, my apologies, I used the ICODE link and not the CODE one)
# 4  
Old 11-17-2016
Can you tell what command is doing this - by "this" I think you have programs (commands) running in the foreground/background that are causing this problem.

There isn't enough of the script posted to find the problem.

An example: mycommand is a command that normally runs in the background, does its job, then may or may not output to the screen. If you start it in the foreground it looks like it "hangs". It is just running normally. Try to work with that concept and see what you get. What you posted should by itself not behave that way.
# 5  
Old 11-18-2016
I am definitely stumped. When I run with
Code:
set -x

, I can see everything being output. However, whenever I run it without it, the output from the called functions is suppressed until they return back to the function that did the initial calling. That said, here is the complete code:

Code:
#====================================================================================
# Error handler functions
#====================================================================================
function bomb
{
cat << eof

*** Invalid selection.  Try again! ***

eof
sleep 1
}

#====================================================================================
# Spinner functions
#====================================================================================
#---------------------------------------------
# Initialize spinner variables
#---------------------------------------------
spinner_items="/-\|"
spinner_count=0
#---------------------------------------------
# Start the spinner
#---------------------------------------------
function spin
{
  printf "\b${spinner_items:spinner_count++:1}"
  ((spinner_count==${#spinner_items})) && spinner_count=0
}

#---------------------------------------------
# Stops the spinner
#---------------------------------------------
function endspin
{
  printf "\r%s\n" "$@"
}

#====================================================================================
# Function to create the input files required by the others processes
#====================================================================================
function Create_Input
{
read -p "Enter customer name: " CUSTOMER
read -p "Are you including OS400-SST data? <Y/N> " SST_DATA
read -p "Do we need to remove customer data? <Y/N> " REMOVE_CUST

#case $SST_DATA in
#  [yY]) make_sst_data
#      ;;
#  [nN]) make_no_sst_data
#       ;;
#  *) bomb
#    ;;
#esac

if [ $SST_DATA = "Y" -o $SST_DATA = "y" ]
then
    fix_files
    echo "Clean and combine files........"
    cd datasource

    for CLEANFILE in *.mef3
    do
      spin
      awk -F\| '(NF==11){print}{}' OFS="|" ${CLEANFILE} > xtmp
      sed -e 's/^M//g' xtmp | awk 1 > xxtmp
      rm xtmp ${CLEANFILE}
      if [ "$REMOVE_CUST" = "Y" -o "$REMOVE_CUST" = "y" ]
      then
        make_ibm_only
        awk -F\| 'toupper($4) ~ /SST/' OFS="|" xtmp6 >> ${CUSTOMER}_SST-input.mef3
        awk -F\| 'toupper($4) !~ /SST/' OFS="|" xtmp6 >> ${CUSTOMER}-input.mef3
        rm xtmp6
      else
        make_ibm_cust
        awk -F\| 'toupper($4) ~ /SST/' OFS="|" xtmp4 >> ${CUSTOMER}_SST-input.mef3
        awk -F\| 'toupper($4) !~ /SST/' OFS="|" xtmp4 >> ${CUSTOMER}-input.mef3
        rm xtmp4
      fi
    done
    endspin
    cd ..
    echo "Process completed - ${CUSTOMER}-input.mef3 created"
    echo "Process completed - ${CUSTOMER}_SST-input.mef3 created"
    echo ""
else
    fix_files
    echo "Clean and combine files........"
    cd datasource

    for CLEANFILE in *.mef3
    do
      spin
      awk -F\| '(NF==11){print}{}' OFS="|" ${CLEANFILE} > xtmp
      sed -e 's/^M//g' xtmp | awk 1 > xxtmp
      rm xtmp
      if [ "$REMOVE_CUST" = "Y" -o "$REMOVE_CUST" = "y" ]
      then
        make_ibm_only
        awk -F\| 'toupper($4) !~ /SST/' OFS="|" xtmp6 >> ${CUSTOMER}-input.mef3
        rm "$CLEANFILE" xtmp6
      else
        make_ibm_cust
        awk -F\| 'toupper($4) !~ /SST/' OFS="|" xtmp4 >> ${CUSTOMER}-input.mef3
        rm "$CLEANFILE" xtmp4
      fi
    done
    endspin
    cd ..
    echo "Process completed - ${CUSTOMER}-input.mef3 created\n\n"
fi
}

#====================================================================================
# Function to create OS DEVICEROLE file
#====================================================================================
function Create_OS_DeviceRole
{
tput clear
read -p "Enter CUSTOMER name: " CUSTOMER
read -p "Enter DOMAIN name: " DOMAIN
read -p "Enter ENUM file name: " ENUM

~/uat/uatEnumServer-DeviceRole.pl -e ${CUSTOMER}-IAM -D ${DOMAIN} -F ${ENUM}
}

#====================================================================================
# Function to create OS DEVICES file
#====================================================================================
function Create_OS_Device
{
tput clear
read -p "Enter CUSTOMER Name: " CUSTOMER
read -p "Enter GACDW file name: " GACDW
read -p "Enter DEVICEROLE file name: " DEVICEROLE
read -p "Enter Delivery team name: " DELIVERY
read -p "Do we have windows data? <Y/N>: " WINDOWS
read -p "Last QEV date <yyyy-mm-dd>: " LAST_QEV
read -p "Last CBN date <yyyy-mm-dd>: " LAST_CBN
read -p "Last PRIV date <yyyy-mm-dd>: " LAST_PRIV

case $WINDOWS in
  Yy) ~/uat/uatGACDW-Migration-Devices.pl -F ${CUSTOMER}-GACDW.csv -d ${DELIVERY} -M ${CUSTOMER}_DEVICEROLE.csv -e ${CUSTOMER} -q ${LAST_QEV} -n ${LAST_CBN} -p ${LAST_PRIV} -f
    ;;
  Nn) ~/uat/uatGACDW-Migration-Devices.pl -F ${CUSTOMER}-GACDW.csv -d ${DELIVERY} -e ${CUSTOMER} -q ${LAST_QEV} -n ${LAST_CBN} -p ${LAST_PRIV}
    ;;
  *) bomb
    ;;
esac
}

#====================================================================================
# Function to create OS Group file
#====================================================================================
function Create_OS_Group
{
tput clear
#set -x
read -p "Enter customer name: " CUSTOMER
read -p "Are you including OS400-SST data? <Y/N> " SST_DATA
read -p "Enter DPE Intermediate Code <*DPEABC> " DPEIC

case $SST_DATA in
  [yY]) ~/uat/uatMEF3-Migration-Groups.pl -e ${CUSTOMER}-IAM -F ${CUSTOMER}_SST-input.mef3 -R ${CUSTOMER}-DEVICES.csv -O ${CUSTOMER}-PO.csv -o ${DPEIC} -g YES -z ${CUSTOMER}_SST
    ~/uat/uatMEF3-Migration-Groups.pl -e ${CUSTOMER}-IAM -F ${CUSTOMER}-input.mef3 -R ${CUSTOMER}-DEVICES.csv -O ${CUSTOMER}-PO.csv -o ${DPEIC} -g YES
    ;;
  [nN]) ~/uat/uatMEF3-Migration-Groups.pl -e ${CUSTOMER}-IAM -F ${CUSTOMER}-input.mef3 -R ${CUSTOMER}-DEVICES.csv -O ${CUSTOMER}-PO.csv -o ${DPEIC} -g YES
    ;;
  *) bomb
    ;;
esac
#set +x
}

#====================================================================================
# Function to create OS User file
#====================================================================================
function Create_OS_User
{
tput clear
read -p "Enter CUSTOMER Name: " CUSTOMER
read -p "Enter DPE Intermediate Code <*DPEABC>:    " DPEIC
read -p "Are you including OS400-SST data? <Y/N>: " SST_DATA

case $SST_DATA in
  [Yy])
    ~/uat/uatMEF3-Migration-Users.pl -e ${CUSTOMER}-IAM -F ${CUSTOMER}_SST-input.mef3 -R ${CUSTOMER}-DEVICES.csv -d ${DPEIC} -z ${CUSTOMER}_SST
    ~/uat/uatMEF3-Migration-Users.pl -e ${CUSTOMER}-IAM -F ${CUSTOMER}-input.mef3 -R ${CUSTOMER}-DEVICES.csv -d ${DPEIC} 
    ;;
  [Nn])
    ~/uat/uatMEF3-Migration-Users.pl -e ${CUSTOMER}-IAM -F ${CUSTOMER}-input.mef3 -R ${CUSTOMER}-DEVICES.csv -d ${DPEIC}
    ;;
  *) bomb
    ;;
esac
}

#====================================================================================
# Function to create OS RECONCILIATION file
#====================================================================================
function Create_OS_Recon
{
tput clear
read -p "Enter customer name: " CUSTOMER
read -p "Are you including OS400-SST data? <Y/N> " SST_DATA
read -p "Do you need to keep FQDN hostnames? <Y/N> " KEEP_FQDN
read -p "Do you wish to split output files by platform? <Y/N> " SPLIT_FILES

case $SST_DATA in
  [Yy])
    make_sst_recon
    ;;
  [Nn])
    make_no_sst_recon
    ;;
  *) bomb
    ;;
esac
}

#====================================================================================
# Function to clean up the MEF3 and create our input file
#====================================================================================
function make_sst_recon
{
if [ "$KEEP_FQDN" = "N" -o "$KEEP_FQDN" = "n" ]
then
  ~/uat/uatMEF3-Reconciliation.pl -e ${CUSTOMER}-IAM -R ${CUSTOMER}-DEVICES.csv -F ${CUSTOMER}-input.mef3
  ~/uat/uatMEF3-Reconciliation.pl -e ${CUSTOMER}-SST -R ${CUSTOMER}-DEVICES.csv -F ${CUSTOMER}_SST-input.mef3 -z ${CUSTOMER}_SST

  cd result
  sed -e 's/-SST:/:/' ${CUSTOMER}-IAM_RECONCILIATION.csv > tmpx
  mv tmpx ${CUSTOMER}-IAM_RECONCILIATION.csv
  cd ..
else
  ~/uat/uatMEF3-Reconciliation.pl -e ${CUSTOMER}-IAM -R ${CUSTOMER}-DEVICES.csv -F ${CUSTOMER}-input.mef3 -q
  ~/uat/uatMEF3-Reconciliation.pl -e ${CUSTOMER}-SST -R ${CUSTOMER}-DEVICES.csv -F ${CUSTOMER}_SST-input.mef3 -z ${CUSTOMER}_SST -q

  cd result
  sed -e 's/-SST:/:/' ${CUSTOMER}-IAM_RECONCILIATION.csv > tmpx
  mv tmpx ${CUSTOMER}-IAM_RECONCILIATION.csv
  cd ..
fi

if [ "$SPLIT_FILES" = "Y" -o "$SPLIT_FILES" = "y" ]
then
  make_split
fi
}

#====================================================================================
# Function to make recon files without SST data
#====================================================================================
function make_no_sst_recon
{
if [ "$KEEP_FQDN" = "N" -o "$KEEP_FQDN" = "n" ]
then
  ~/uat/uatMEF3-Reconciliation.pl -e ${CUSTOMER}-IAM -R ${CUSTOMER}-DEVICES.csv -F ${CUSTOMER}-input.mef3
else
  ~/uat/uatMEF3-Reconciliation.pl -e ${CUSTOMER}-IAM -R ${CUSTOMER}-DEVICES.csv -F ${CUSTOMER}-input.mef3 -q
fi

if [ "$SPLIT_FILES" = "Y" -o "$SPLIT_FILES" = "y" ]
then
  make_split
fi
}

#====================================================================================
# Function to create SubSystem DEVICE/USER/GROUP files - one script does it all
#====================================================================================
function Create_SS_Migration
{
tput clear
read -p "Enter customer name: " CUSTOMER
read -p "Enter DPE Intermediate Code <*DPEABC> " DPEIC

~/uat/uatSubsystem-Migration.pl -e ${CUSTOMER}-IAM -F ${CUSTOMER}-input.mef3 -P ${CUSTOMER}-PO.csv -D ${CUSTOMER}-DEVICES.csv -T ${CUSTOMER}-DELIVERY.csv -d ${DPEIC} -A -B -C
}

#====================================================================================
# Function to create SubSystem RECONCILIATION files
#====================================================================================
function Create_SS_Recon
{
tput clear
read -p "Enter customer name: " CUSTOMER

~/uat/uatSubsystem-Reconciliation.pl -e ${CUSTOMER}-IAM -F ${CUSTOMER}-input.mef3 -D ${CUSTOMER}-DEVICES.csv
}

#====================================================================================
# Function to create DEVICES file for SHARED userIDs
#====================================================================================
function Create_SharedID_Devices
{
tput clear
read -p "Enter CUSTOMER Name: " read CUSTOMER
read -p "Enter SID file name: " read SID_FILE
read -p "Enter Delivery file name: " read DELIVERY

~/uat/uatGIAMA-Migration-SharedID-DEVICES.pl -e ${CUSTOMER}-SHID -F ${SID_FILE} -D ${CUSTOMER}-DELIVERY.csv

}

#====================================================================================
# Function to create the file to load USERS to UAT
#====================================================================================
function Create_SharedID_Users
{
tput clear
read -p "Enter CUSTOMER Name: " read CUSTOMER
read -p "Enter SID file name: " read SID_FILE
read -p "Enter DPE Intermediate Code <*DPEABC> " DPEIC

~/uat/uatGIAMA-Migration-SharedID-SHIDEnvironment.pl -e ${CUSTOMER}-SHID -F ${SID_FILE} -D ${CUSTOMER}-DELIVERY.csv -E ${DPEIC}
}

#====================================================================================
# Function to create the file to promote userIDs to SHARED status
#====================================================================================
function Create_SharedID_SHAREDID
{
tput clear
read -p "Enter CUSTOMER Name: " read CUSTOMER
read -p "Enter SID file name: " read SID_FILE
read -p "Enter DPE Intermediate Code <*DPEABC> " DPEIC

~/uat/uatGIAMA-Migration-SharedID-USERS.pl -e ${CUSTOMER}-SHID -F ${SID_FILE} -O ${CUSTOMER}-OWNER.csv
}


#====================================================================================
# Function to check for missing MEF3 files
#====================================================================================
function Check_missing_mef
{
tput clear
read -p "Enter CUSTOMER name: " CUSTOMER
echo ""
echo "Comparing files to see if we have missing MEF3 data..."

cut -d\| -f3 datasource/${CUSTOMER}-input.mef3 | sort -u > input_devices
cut -d: -f1 result/${CUSTOMER}-DEVICES.csv > result_devices
touch result/${CUSTOMER}-MISSING_MEF3.csv
cp /dev/null result/${CUSTOMER}-MISSING_MEF3.csv

grep -iv -F -x -f input_devices result_devices > result/${CUSTOMER}-MISSING_MEF3.csv

echo ""
echo "Servers with missing MEF3 data are reported in result/${CUSTOMER}-MISSING_MEF3.csv"
}

#====================================================================================
# Function to fix output file device environments
# This function is to fix the environment for Domains
#====================================================================================
function Fix_output_environments
{
tput clear
case $SST_DATA in
  [Yy])
    echo "function not done yet..."
    ;;
  [Nn])
    echo "function not done yet..."
    ;;
  *) bomb
    ;;
esac
}

#====================================================================================
# Function to make input files when SST data is provided
#====================================================================================
function make_ibm_only
{
  awk -F\| 'toupper($7) ~ /\/I\/|\/E\/|\/N\/|\/T\/|\/S\/|\/F\/|\/V\/\*/' OFS="|" xxtmp > xtmp2
  rm xxtmp
  awk -F\| '{gsub(/^[ \t]+|[ \t]+$/,"",$3)}1' OFS="|" xtmp2 > xtmp3
  rm xtmp2
  awk -F\| '{gsub(/^[ \t]+|[ \t]+$/,"",$10)}1' OFS="|" xtmp3 > xtmp4
  rm xtmp3
  awk -F\| '{gsub(/^[ \t]+|[ \t]+$/,"",$11)}1' OFS="|" xtmp4 > xtmp5
  rm xtmp4
  awk -F\| '{gsub(/\47/,""); print $0}' OFS="|" xtmp5 > xtmp6
  rm xtmp5
}

#====================================================================================
# Function to make input files when SST data is provided
#====================================================================================
function make_ibm_cust
{
  awk -F\| '{gsub(/^[ \t]+|[ \t]+$/,"",$3)}1' OFS="|" xxtmp > xxxtmp
  rm xxtmp
  awk -F\| '{gsub(/^[ \t]+|[ \t]+$/,"",$10)}1' OFS="|" xxxtmp > xtmp2
  rm xxxtmp
  awk -F\| '{gsub(/^[ \t]+|[ \t]+$/,"",$11)}1' OFS="|" xtmp2 > xtmp3
  rm xtmp2
  awk -F\| '{gsub(/\47/,""); print $0}' OFS="|" xtmp3 > xtmp4
  rm xtmp3
}

#====================================================================================
# Function to fix file names with spaces
#====================================================================================
function fix_files
{
echo "Removing spaces from any files names......."
cd datasource

for SPACEFILE in *.mef3
do
  spin
  mv "$SPACEFILE" `echo $SPACEFILE | tr ' ' '_'` > /dev/null 2>&1
done
endspin
echo "Done removing spaces from any files names......."

echo "Fixing DEVICE file issues......."
cd ../result
sort ${CUSTOMER}-DEVICES.csv > xtmp
sed -e 's/"//g' xtmp > ${CUSTOMER}-DEVICES.csv
cd ..
echo "Done fixing DEVICE file......."
}

#====================================================================================
# Function to clean up the MEF3 and create our input file
#====================================================================================
function make_split
{
echo "Splitting data by platform......"
cd result

# get server|platform combinations
awk -F\| '{print $3,$4}' OFS="|" ../datasource/${CUSTOMER}-input.mef3 | sort -u > servers_platforms

# get domain entries as there won't be a physical mef3 file for these and add server|platform info
grep -i ":DOMAIN:" ${CUSTOMER}-DEVICES.csv > domains
while read DOMAIN
do
  H1=`echo "$DOMAIN" | cut -d: -f1`
  echo "$H1\|Windows" >> servers_platforms
done < domains

awk -F\| '{print $2}' servers_platforms | sort -u > platforms

# create by platform server lists
while read PLATFORM
do
  P1=`echo "$PLATFORM" | tr ' ' '_'`
  P2=`echo "$P1" | tr '-' '_'`
  grep -i "$PLATFORM" servers_platforms | cut -d: -f1 >> ${P2}-hosts
done < platforms

# process by server lists to split output recon file
for HOSTS in *-hosts
do
  P3=`echo ${HOSTS} | cut -d"-" -f1`
  while read LINE
  do
    spin
    SEARCH=`echo $LINE | cut -d\| -f1`
    grep -i ":$SEARCH:" ${CUSTOMER}-IAM_RECONCILIATION.csv >> ${CUSTOMER}-${P3}_RECONCILIATION.csv
  done < ${HOSTS}
  sort -u ${CUSTOMER}-${P3}_RECONCILIATION.csv > x
  mv x ${CUSTOMER}-${P3}_RECONCILIATION.csv
done
endspin

rm platforms *-hosts servers_platforms ${CUSTOMER}-IAM_RECONCILIATION.csv domains
cd ..
echo "Done splitting data by platform......\n\n"
}

#====================================================================================
# Code to build a menu system
#====================================================================================
E='echo -e'
e='echo -en'
trap "R;exit" 2
ESC=$( $e "\e")
TPUT(){ $e "\e[${1};${2}H";}
CLEAR(){ $e "\ec";}
CIVIS(){ $e "\e[?25l";}
DRAW(){ $e "\e%@\e(0";}
WRITE(){ $e "\e(B";}
MARK(){ $e "\e[7m";}
UNMARK(){ $e "\e[27m";}
R(){ CLEAR ;stty sane;$e "\ec\e[37;44m\e[J";};
HEAD(){ DRAW
           for each in $(seq 1 20);do  # increase second number by 1 if you add a new menu item
           $E "               x                                                x"
           done
           WRITE;MARK;TPUT 1 20  # increase second number by 1 if you add a new menu item
           $E "UAT FILE MANIPULATION MENU                ";UNMARK;}
           i=0; CLEAR; CIVIS;NULL=/dev/null
FOOT(){ MARK;TPUT 19 20  # increase both by 1 if you add a new menu item
           printf "ARROW UP/DOWN TO SELECT - HIT ENTER   ";UNMARK;}
ARROW(){ read -s -n3 key 2>/dev/null >&2
           if [[ $key = $ESC[A ]];then echo up;fi
           if [[ $key = $ESC[B ]];then echo dn;fi;}

M0(){ TPUT  4 20; $e "Create INPUT mef3 files              ";}
M1(){ TPUT  5 20; $e "Create OS DEVICEROLE files           ";}
M2(){ TPUT  6 20; $e "Create OS DEVICES files              ";}
M3(){ TPUT  7 20; $e "Create OS GROUPS files               ";}
M4(){ TPUT  8 20; $e "Create OS USERS files                ";}
M5(){ TPUT  9 20; $e "Create OS RECONCILIATION files       ";}
M6(){ TPUT 10 20; $e "Create SUBSYSTEM migration files     ";}
M7(){ TPUT 11 20; $e "Create SUBSYSTEM RECONCILIATION files";}
M8(){ TPUT 12 20; $e "Check for missing MEF3 files         ";}
M9(){ TPUT 13 20; $e "Fix output file Environments         ";}
M10(){ TPUT 14 20; $e "Create Shared ID Devices file        ";}
M11(){ TPUT 15 20; $e "Create Shared ID Users file          ";}
M12(){ TPUT 16 20; $e "Create Shared ID SHAREDID file       ";}
M13(){ TPUT 17 20; $e "EXIT                                 ";}
LM=13   #increase this by 1 for each new menu option you add

MENU(){ for each in $(seq 0 $LM);do M${each};done;}
POS(){ if [[ $cur == up ]];then ((i--));fi
           if [[ $cur == dn ]];then ((i++));fi
           if [[ $i -lt 0   ]];then i=$LM;fi
           if [[ $i -gt $LM ]];then i=0;fi;}

REFRESH(){ after=$((i+1)); before=$((i-1))
           if [[ $before -lt 0  ]];then before=$LM;fi
           if [[ $after -gt $LM ]];then after=0;fi
           if [[ $j -lt $i      ]];then UNMARK;M$before;else UNMARK;M$after;fi
           if [[ $after -eq 0 ]] || [ $before -eq $LM ];then
           UNMARK; M$before; M$after;fi;j=$i;UNMARK;M$before;M$after;}

INIT(){ R;HEAD;FOOT;MENU;}
SC(){ REFRESH;MARK;$S;$b;cur=`ARROW`;}
ES(){ MARK;$e "Press <RETURN> to return to main menu ";$b;read;INIT;};INIT

#====================================================================================
# Main Routine
#====================================================================================
while [[ "$O" != " " ]] 
do 
    case $i in
        0) S=M0;SC;if [[ $cur == "" ]];then R;$e "\n$(Create_Input)\n";ES;fi;;
        1) S=M1;SC;if [[ $cur == "" ]];then R;$e "\n$(Create_OS_DeviceRole)\n";ES;fi;;
        2) S=M2;SC;if [[ $cur == "" ]];then R;$e "\n$(Create_OS_Device)\n";ES;fi;;
        3) S=M3;SC;if [[ $cur == "" ]];then R;$e "\n$(Create_OS_Group)\n";ES;fi;;
        4) S=M4;SC;if [[ $cur == "" ]];then R;$e "\n$(Create_OS_User)\n";ES;fi;;
        5) S=M5;SC;if [[ $cur == "" ]];then R;$e "\n$(Create_OS_Recon)\n";ES;fi;;
        6) S=M6;SC;if [[ $cur == "" ]];then R;$e "\n$(Create_SS_Migration)\n";ES;fi;;
        7) S=M7;SC;if [[ $cur == "" ]];then R;$e "\n$(Create_SS_Recon)\n";ES;fi;;
        8) S=M8;SC;if [[ $cur == "" ]];then R;$e "\n$(Check_missing_mef)\n";ES;fi;;
        9) S=M9;SC;if [[ $cur == "" ]];then R;$e "\n$(Fix_output_environments)\n";ES;fi;;
        10) S=M10;SC;if [[ $cur == "" ]];then R;$e "\n$(Create_SharedID_Devices)\n";ES;fi;;
        11) S=M11;SC;if [[ $cur == "" ]];then R;$e "\n$(Create_SharedID_Users)\n";ES;fi;;
        12) S=M12;SC;if [[ $cur == "" ]];then R;$e "\n$(Create_SharedID_SHAREDID)\n";ES;fi;;
        13) S=M13;SC;if [[ $cur == "" ]];then R;exit 0;fi;;
    esac
    POS
done

# 6  
Old 11-21-2016
Your code prints the output of menu scripts like this:

Code:
        0) S=M0;SC;if [[ $cur == "" ]];then R;$e "\n$(Create_Input)\n";ES;fi;;

e is defined as e='echo -en'

I'd suggest using stderr for your spin

Code:
function spin
{
  printf "\b${spinner_items:spinner_count++:1}" >&2
  ((spinner_count==${#spinner_items})) && spinner_count=0
}

This User Gave Thanks to Chubler_XL For This Post:
# 7  
Old 01-12-2017
So after much playing around with this, it really came down to a simple command that often gets overlooked. I just had to use the
Code:
 tee

command to redirect the output back to the screen. I just captured the tty that I was on to a variable first. Sample of what I did is here:


Code:
TTY=`tty`
myscript.pl -switch1 -switch2 | tee $TTY

This User Gave Thanks to dagamier For This Post:
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: problem with a function which use colors

Hello guys :) I've a some issue with a function which use the bash colors in my script. An example : #!/bin/bash set -x log_in(){ host="srv1" remote_files="log/" LOG_FILE="logfile" green='\033]; then color_in_red=("${red}"$2"${none}") echo -e... (2 Replies)
Discussion started by: Arnaudh78
2 Replies

2. Shell Programming and Scripting

Bash function, for BSD

I am putting this thread to shell-threads, because it is about how to make a function work properly. I need a hint for declaring a function right, it has been more than a year I did not work that straight with bash. So my aim is to turn off the eth0 (as it would be in linux, and bge0 in bsd ),... (2 Replies)
Discussion started by: 1in10
2 Replies

3. Shell Programming and Scripting

Yes or No selection within bash function

I need to add a selection within the bash function below and am having some trouble doing so. phox2b() { printf "\n\n" printf "What is the id of the patient getting Phox2B analysis : "; read id printf "Is this an intronic variant? Y/N "; read match_choice case... (5 Replies)
Discussion started by: cmccabe
5 Replies

4. UNIX for Dummies Questions & Answers

Bash INKEY$ function...

This is probably common knowledge to the professionals but not so much for amateurs like myself. This is a code snippet for the equivalent of BASIC's... LET char$=INKEY$ As the timeout parameter cannot be less than 1 second then this is the only limitation... It is a single line... (5 Replies)
Discussion started by: wisecracker
5 Replies

5. Shell Programming and Scripting

Bash function

startvm() { startguest } Is there a way use one line to get this ? actually I want startvm=startguest (5 Replies)
Discussion started by: yanglei_fage
5 Replies

6. Shell Programming and Scripting

BASH function error

Hey everyone. I am currently testing my first function based BASH script. The ultimate goal is going to be moving logs from point A to point B (or if B is down, to point C). Part of this involves the following function: function testAlive{ ping -c 1 -q $1 } Now when I run ping -c... (1 Reply)
Discussion started by: msarro
1 Replies

7. UNIX for Advanced & Expert Users

AWK sub function curious problem under bash

I need to detect the number of pages in a print job when it is available so I can warn users when they try to print a report much larger than they expected. Sometimes they are trying to print 1000 page reports when they thought they were getting a 10 page report. Under linux I am scanning the... (5 Replies)
Discussion started by: Max Rebo
5 Replies

8. Shell Programming and Scripting

bash search function

I want to have a function with a similar interface: search *.cpp asdf that will search recursively all directories for *.cpp file, containing line 'asdf' inside. I tried this: function search { find . -name "$1" | xargs grep -li $2; } But it doesn't work all the time. For example, if i run it... (3 Replies)
Discussion started by: doze
3 Replies

9. Shell Programming and Scripting

Need help in using power function in Bash

Hi, I would like to use a power function in Bash in an awk '{ } . e.g pow(2,3)=8 Any suggestion? I try to find online resources but most of them stated by using BC. Please advise. Thanks. (3 Replies)
Discussion started by: ahjiefreak
3 Replies

10. Shell Programming and Scripting

Need assistance with bash function

Hi all! I need a little help with an imbedded fuction I am trying to write. What I am trying to do is go to a series of hosts and get the contents of an XML file, storing some of the data, along with the name of the host it was gathered from. My intent is to store this in an array for later... (1 Reply)
Discussion started by: _jade_
1 Replies
Login or Register to Ask a Question