How to read in a part of an echo line?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to read in a part of an echo line?
# 8  
Old 10-31-2012
I think what we were trying to say was : first, you should focus on how to use a "case" statement, which is more appropriate to what you are trying to do and easy to read and maintain.

Then, if you want to investigate further, you should also train to use "getopts" as well as "select". (see the links previously provided)
This User Gave Thanks to ctsgnb For This Post:
# 9  
Old 10-31-2012
Thanks Pamu but it doesn't work for what I want as I can't pass the $1 until I've been shown the options.
# 10  
Old 10-31-2012
Quote:
Originally Posted by Grueben
Thanks Pamu but it doesn't work for what I want as I can't pass the $1 until I've been shown the options.
So who is stopping you from doing this..?

You can do something like this.

Code:
echo "Options are"
echo "1 for --"
echo "2 for --"
read opt
#You can check is $opt is present or not
case "$opt" in

1)  echo "Sending 1 signal"
    ;;
2)  echo  "Sending 2 signal"
    ;;
3)  echo  "Sending 3 signal"
    ;;
*) echo "Signal number $opt is not processed"
   ;;
esac

I hope this helpsSmilie

pamu
This User Gave Thanks to pamu For This Post:
# 11  
Old 10-31-2012
Are you struggling with the logic for the menu driven cd Grueben? Maybe this code snipplet can help (tested in bash, but it should work with ksh too):
Code:
#!/bin/bash

dir=""
backmsg="Back to menu"
PS3="Select directory to cd into: "

while [ "$dir" != "$backmsg" ]
do
   alldirs=$(ls -ap |grep /)
   select dir in $alldirs "$backmsg"
   do
      if [ "$dir" != "$backmsg" ]
      then
         cd $dir
         pwd
      fi
      break
   done
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to make a loop to read the input from a file part by part?

Hi All, We've a VDI infrastructure in AWS (AWS workspaces) and we're planning to automate the process of provisioning workspaces. Instead of going to GUI console, and launching workspaces by selecting individual users is little time consuming. Thus, I want to create them in bunches from AWS CLI... (6 Replies)
Discussion started by: arun_adm
6 Replies

2. Shell Programming and Scripting

Echo printing a line in 2 lines; expected to print in one line

Dear All, fileName: therm.txt nc3h7o2h 7/27/98 thermc 3h 8o 2 0g 300.000 5000.000 1390.000 41 1.47017550e+01 1.71731699e-02-5.91205329e-06 9.21842570e-10-5.36438880e-14 2 -2.99988556e+04-4.93387892e+01 2.34710908e+00 4.34517484e-02-2.65357553e-05 3 ... (7 Replies)
Discussion started by: linuxUser_
7 Replies

3. Shell Programming and Scripting

How to read each line from input file, assign variables, and echo to output file?

I've got a file that looks like this (spaces before first entries intentional): 12345650-000005000GL140227 ANNUAL HELC FEE EN 22345650-000005000GL140227 ANNUAL HELC FEE EN 32345650-000005000GL140227 ANNUAL HELC FEE EN I want to read through the file line by line,... (6 Replies)
Discussion started by: Scottie1954
6 Replies

4. Shell Programming and Scripting

Replacing part of the sentence using echo and sed

Hi, Iam using ksh and trying to execute the following syntax to replace one word of the sentence with a new word. But somehow sed is not able to replace the old value with new value. Please let me know where Iam going wrong. Sample Code : --> export line="VORTEX,abcdef" export... (3 Replies)
Discussion started by: ajithab
3 Replies

5. Shell Programming and Scripting

[Solved] Printing a part of the last line of the specific part of a file

Hi, I have 80 large files, from which I want to get a specific value to run a Bash script. Firstly, I want to get the part of a file which contains this: Name =A xxxxxx yyyyyy zzzzzz aaaaaa bbbbbb Value = 57 This is necessary because in a file there are written more lines which... (6 Replies)
Discussion started by: wenclu
6 Replies

6. Shell Programming and Scripting

read variable after echo

Hi, i want to create an user-friendly script where you are asked for two numbers. i would like that these two number to be separated with "--" for example, but i can't figure out how to do this. for example read -p "Insert lowest and highest value: " min ; echo -n "-- "; read max so... (3 Replies)
Discussion started by: ezitoc
3 Replies

7. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

8. UNIX for Dummies Questions & Answers

echo appends to a read-only file

echo command can append to a read-only file too. If the file is read-only, with w flag removed, then even echo should not be able to append to the file. But it is possible. Can anybody explain the below behaviour? /root > echo 'sample text' > file /root > cat file sample text /root >... (2 Replies)
Discussion started by: anand_bh
2 Replies

9. Shell Programming and Scripting

While read do, then echo, gives double output

Sorry about the title, but this should be fairly self-explanatory. My script seems to work, except that in the output, below, the first three lines are correct, but why does it print the additional lines 4, 5, & 6? Script: #!/bin/bash while read; do client="$(grep -m 1 Client | awk... (3 Replies)
Discussion started by: MrKen
3 Replies

10. Shell Programming and Scripting

how to read a file to an echo statement

I was searching for an option where i can echo some strings together with the contents of a file. Eg. I was to echo the below string to a file "alter application PMS_ add variable CurrYear Y2009;" >> ${ESS_MAXL_DIR}/PMS_SUB.txt The value 2009 is coming from a file called date.txt without the... (3 Replies)
Discussion started by: Celvin VK
3 Replies
Login or Register to Ask a Question