Sponsored Content
Top Forums Shell Programming and Scripting [Solved] Use of until loop for user confirmation Post 302630481 by anuragpgtgerman on Wednesday 25th of April 2012 10:13:47 PM
Old 04-25-2012
[Solved] Use of until loop for user confirmation

Below is my script that is using to rename the name of file .Here I am using two methods to pass the both arguments wih script name or run the script and give the input one by one.But my issue is I want to rename the name of the file if user select Y(y) then it should rename the file else select N(n) then it should exit from the script.I am using until but I think I am doing something wrong.Can you help me on this where I am wrong

Code:
ConfY_N=Y
ConfY_N=N
## Prompt Arg4
##
prompt_IM_StartDt ()
{
 echo -e "\n\nUser will enter Start Time here : ";
 read IM_StartDt;
}
##
## Set Arg4
##
set_IM_StartDt ()
{
 ## Fetching Start Date for Product Classification folder.
 IM_StartDt="";
 if [[ -z "${IM_StartDt}" ]]; then prompt_IM_StartDt; fi
}
# ----------------------------------------------------------------------------------------------------------------
## Prompt Arg5
##
prompt_IM_CloseDt ()
{
 echo -e "\n\nUser will enter Start Time here : ";
 read IM_CloseDt;
}
##
## Set Arg5
##
set_IM_CloseDt ()
{
 ## Fetching Close Date for Product Classification folder.
 IM_CloseDt="";
 if [[ -z "${IM_CloseDt}" ]]; then prompt_IM_CloseDt; fi
## Give priority to passed parameters first.
IM_StartDt="${1}";
IM_CloseDt="${2}";

#copy ()
#{
#mv ${IM_StartDt} ${IM_CloseDt}
#}
## Check arguments and set them if reqd.
## -------------------------------------
for arg in IM_StartDt:${IM_StartDt} IM_CloseDt:${IM_CloseDt};
do
  ## Get Var/Val pair
  var="${arg%:*}";
  val="${arg#*:}";
  ## Check IM variable null condition. If not set, find it from Master config file. If Master config file doesn't store the value, prompt the user (last option).
  if [[ -z "${val}" ]]; then
     set_${var};
  fi
done
#copy
until [[ $ConfY_N == "Y" ]];
do
  echo -e "\n\n\n#########################################################################################################\n";
  echo -n "- User Confirmation required, please enter (Y to continue -OR N to stop/exit gracefully): "; read ConfY_N;
                
## DONT show the below echo on Screen STDOUT. Use >>.
  ConfY_N="$(echo ${ConfY_N} | tr a-z A-Z)";
  echo -e "\n# User Selected: \"${ConfY_N}\" ####################################################################################\n\n\n";
  copy
  if [[ "${ConfY_N}" == "N" ]];
  then
      echo -e "User requested to EXIT out gracefully.\n\n";
      #echo -e "`show_script_data`";);
      exit;
      fi
done
copy ()
{
mv ${IM_StartDt} ${IM_CloseDt}
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[SOLVED] for loop to process files

I need to process a dirtree containing ms office files such that each file is stored as a variable and also, just the file file stem. Why? They will be using as input and output parameters for another script. For example /path/to/second_script -i filename.docx -o filename Here's what I... (1 Reply)
Discussion started by: graysky
1 Replies

2. Shell Programming and Scripting

[Solved] Endless while loop when compare files

Hi All, I've written a script to read 2 files and compare the contents using while loop but somehow when $line is not found in test2, the script will continue looping. Below is my code, pls advise what could went wrong TIA Nick for line in test1.txt | while read line do grep -i... (4 Replies)
Discussion started by: Nick1971
4 Replies

3. UNIX for Dummies Questions & Answers

[Solved] Simple while loop does not exit

spath="/home/user/k/${1}" dpath="/home/user/seq/Nov17/${1}" cd $dpath ls -1 $spath > list c=1 while read list newlist=`echo $list | sed 's/.gz//' ` newnewlist=`echo $newlist | sed 's/.fastq//' ` do echo $c echo $list c=$(($c+1)) (6 Replies)
Discussion started by: analyst
6 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Syntax error for awk in a loop

can some one please tell me what is the problem with my syntax:confused: I have 100 files in one folder 1. want to read each of the line by line 2. calculate their number of the words between the first word and the last word of each line 3. create file for each file with number of words... (8 Replies)
Discussion started by: A-V
8 Replies

5. Shell Programming and Scripting

[solved] Question for using variables outside a while loop

I want to get newvar outside the while any ideas? while read myline; do var=${myline} newvar1=$(let "$var") done echo $newvar1 I found it its ok now Thank you! (0 Replies)
Discussion started by: sanantonio7777
0 Replies

6. Shell Programming and Scripting

[Solved] Simple script not working- for loop

Hi all, Please guide me writing this script Follwing is the file which I have created, which contains the files to be copied. cat system1-dr.txt /etc/passwd /etc/shadow /etc/group /etc/vfstab /etc/profile /etc/default/init /etc/shells /etc/dfs/dfstab /etc/dfs/sharetab... (11 Replies)
Discussion started by: manalisharmabe
11 Replies

7. Shell Programming and Scripting

[Solved] Issue with using for loop as for in {2..6} in korn shell

Hi i have to cut columns 2 to 6 from a file and assign it to arrays , The following code works for ctcol in 2 3 4 5 6; do set -A a$ctcol $(cut -d, -f $ctcol test_file) done how ever this does not work for ctcol in {2..6}; do set -A a$ctcol $(cut -d, -f $ctcol test_file)... (4 Replies)
Discussion started by: 100bees
4 Replies

8. Shell Programming and Scripting

[Solved] Problem with if-then-else loop

Hi, i have a problem with this script: for i in $(cat list_ip_switch) do if if ; then echo "found ip" else echo "not found ip" fi done cat list_ip_switch 10.155.249.171 10.155.249.172 (3 Replies)
Discussion started by: elilmal
3 Replies

9. Shell Programming and Scripting

[Solved] For loop help

Hello, This is really breaking my head. I request you help to solve this problem. I have a list of files at the source directory (/tmp) as below, NewTransfer_20131202_APAC.dat NewTransferFile_20131202_APAC.dat NewTransfer_20131203_APAC.dat NewTransferFile_20131203_APAC.dat... (3 Replies)
Discussion started by: sravicha
3 Replies

10. UNIX for Dummies Questions & Answers

How to shutdown Linux box with user confirmation?

Hi Guru's Am looking for linux reboot command which get executed after user confirmation .Can someone please help me with this.:confused::confused::confused: (6 Replies)
Discussion started by: kapil514
6 Replies
escape(1)							Mail Avenger 0.8.3							 escape(1)

NAME
escape - escape shell special characters in a string SYNOPSIS
escape string DESCRIPTION
escape prepends a "" character to all shell special characters in string, making it safe to compose a shell command with the result. EXAMPLES
The following is a contrived example showing how one can unintentionally end up executing the contents of a string: $ var='; echo gotcha!' $ eval echo hi $var hi gotcha! $ Using escape, one can avoid executing the contents of $var: $ eval echo hi `escape "$var"` hi ; echo gotcha! $ A less contrived example is passing arguments to Mail Avenger bodytest commands containing possibly unsafe environment variables. For example, you might write a hypothetical reject_bcc script to reject mail not explicitly addressed to the recipient: #!/bin/sh formail -x to -x cc -x resent-to -x resent-cc | fgrep "$1" > /dev/null && exit 0 echo "<$1>.. address does not accept blind carbon copies" exit 100 To invoke this script, passing it the recipient address as an argument, you would need to put the following in your Mail Avenger rcpt script: bodytest reject_bcc `escape "$RECIPIENT"` SEE ALSO
avenger(1), The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
escape is designed for the Bourne shell, which is what Mail Avenger scripts use. escape might or might not work with other shells. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 escape(1)
All times are GMT -4. The time now is 04:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy