Multiple entries for shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple entries for shell
# 1  
Old 10-21-2014
Multiple entries for shell

I have a simple shell file (convert.sh), that I would like to add a loop to that allows the user to have the "Enter ID:" prompt keep displaying until end is typed.

So instead of:
Code:
bash ~/convert.sh
Enter ID:123
bash ~/convert.sh
Enter ID:456
bash ~/convert.sh
Enter ID:789

The user would enter
Code:
bash ~/covert.sh
Enter ID:123
Next ID: 456
Next ID:789
Next ID:end (shell exits)

Thank you Smilie.

Code:
 #!/bin/bash
echo -n "Enter ID  : "; read id
perl convert2annovar.pl -includeinfo -format vcf4old ${id}_matched.vcf > ${id}_matched.avinput

# 2  
Old 10-21-2014
"echo -n" is not portable, but "printf" works the same everywhere.

Code:
while true
do
        printf "Enter ID  : " ; read id
        [ -z "$id" ] && break
        [ "$id" = "end" ] && break
        perl convert2annovar.pl -includeinfo -format vcf4old ${id}_matched.vcf > ${id}_matched.avinput
done

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 10-21-2014
I apologize for forgetting all the code tags.

---------- Post updated at 10:20 AM ---------- Previous update was at 10:14 AM ----------

Code:
 [ "$id" = "end" ] && break

is it possible to exit cygwin if end is typed? Thanks.
# 4  
Old 10-21-2014
Explain the difference between exiting the script and exiting cygwin, please.

If you mean "close the terminal", I wouldn't expect the terminal to stick around unless it was expecting user input -- i.e. was an interactive shell. In which case your script was ran incorrectly, rather than it quitting incorrectly.

How are you running your script?
# 5  
Old 10-21-2014
exiting the script the terminal stays open, exiting cygwin the terminal closes.

I change directories and run:
Code:
 bash ~/convert.sh

I enter id's until there are no more then type end and the terminal stays open. Thanks Smilie.
# 6  
Old 10-21-2014
If you ran it from a batch file by double clicking it, I think it would close. Otherwise, that's beyond cygwin's control unless you start fiddling with blunt and impolite things like kill (which would only work questionably well with pure Windows things anyway).
# 7  
Old 10-21-2014
Thank you Smilie.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Export Oracle multiple tables to multiple csv files using UNIX shell scripting

Hello All, just wanted to export multiple tables from oracle sql using unix shell script to csv file and the below code is exporting only the first table. Can you please suggest why? or any better idea? export FILE="/abc/autom/file/geo_JOB.csv" Export= `sqlplus -s dev01/password@dEV3... (16 Replies)
Discussion started by: Hope
16 Replies

2. Shell Programming and Scripting

Reducing multiple entries in a tri-lingual dictionary to single entries

Dear all, I am editing a tri-lingual dictionary for open source which has the following data structure English headwords <Tab>Devanagari Headwords<Tab>PersoArabic headwords as in the example below to mark, to number अंगणु (اَنگَڻُ) The English headword entry has at times more than one word,... (2 Replies)
Discussion started by: gimley
2 Replies

3. Shell Programming and Scripting

Shell Script for viewing multiple logs from multiple server

I am new to Shell scripting and below is my requirement. I need to search some specific word e.g. "exception" or "transaction" from log file. We have multiple env e.g. Level1 , Level2 etc and each env have Multiple boxes e.g. For Level 1 env we have "test11.test.com" , "test12.test.com". Each... (1 Reply)
Discussion started by: peeyush
1 Replies

4. Shell Programming and Scripting

Returning multiple values in Shell

Hi I have a code as the following #!/usr/bin/ksh set -x row() { a=$1 b=$2 c=$(($a + $b)) d=$(($a * $b)) echo $a $b } e=`row 2 3` set $e echo "The value of c is $c" echo "The value of d is $d" My requirement is I need to pass two arguments to a function and return two values... (5 Replies)
Discussion started by: Priya Amaresh
5 Replies

5. Shell Programming and Scripting

Need help with shell script using multiple awks

I have a command lline script that works perfectly. cat <some_filename> | awk '$9 == 200' | awk '$10 == 10623720' | awk -F\" '{print $6}' | sort | uniq -c | sort -r I want to put this in a shell script so that we do this for multiple files(all read from a file list) and write each output to... (5 Replies)
Discussion started by: ampak
5 Replies

6. Shell Programming and Scripting

help with multiple loops in shell script

Hi Guys- I'm trying to write a script which takes date as input (mm.yy.dd) and search in the current file. If pattern doesn't exist it will then look in a backup directory and so on. being a newb i'm unable to loop over to the backup directory. hoping for some ideas, i've highlighted the... (1 Reply)
Discussion started by: Irishboy24
1 Replies

7. Shell Programming and Scripting

shell script for multiple logging

Hi All, I am preparing a script which executes following things: 1) Logs into 8 cluster one by one. 2) After logging into each cluster,it prints the cluster name & then exit from that cluster. 3) Then it logs to next cluster & peform the same task. Here is what i have written : for... (8 Replies)
Discussion started by: d8011
8 Replies

8. Shell Programming and Scripting

Shell script to run a python program on multiple entries in a file

Hello I am trying to run a python program using shell script, which takes a single argument from a file. This file has one entry per line : 1aaa 2bbb 3ccc 4ddd 5eee ... ... ... My shell script runs the program, only for the last entry : #!/bin/sh IFS=$'\n' for line in $(cat... (2 Replies)
Discussion started by: ad23
2 Replies

9. Shell Programming and Scripting

Multiple lines into one using PERL or SHELL

Hi All, I need your help to solve problem using either PERL script or SHELL script. We are receving a file, in which one record is coming in multiple rows. The main problem is, we are not able to differenciate when the 1st record ends and where the second record starts. For example, ... (4 Replies)
Discussion started by: Amit.Sagpariya
4 Replies

10. Shell Programming and Scripting

Multiple paramters to a shell script

Hi All, Can anyone tell me how to pass and handle 'N' parameters in a shell script. Thanks, Sumesh (2 Replies)
Discussion started by: sumesh.abraham
2 Replies
Login or Register to Ask a Question