I need to make a select menu that gives options dynamically based on whether certain files are available. For instance:
PS3="Open which readme? "
select readme in This That
do
case "$readme" in
This) open -a /Applications/TextEdit.app This.txt;;
That) open -a /Applications/TextEdit.app That.txt;;
* ) echo "Invalid selection";;
esac
done
}
The catch is that if the file doesn't exist, it should not show in the menu, either. I'm fairly new to shell scripting, so any help would be appreciated.
Thanks for the example. I follow the logic for making a list of existing files, but it's the case statement that is confusing me. I'm not sure what to put in the 'options' section (talk about irony - that's where you stopped). This is the output (no options selectable):
1) This.txt
2) That.txt
#?
If I select either option, it returns Invalid Selection.
Well, I would go this....
So I would put one entry in the case statement for each item in the "for" loop. I don't see any value in using the array syntax.
Google's right in that you need to use the braces. But an additional problem is that the array is zero based. The first subscript should be zero, not one.
But switching to correct subscripts still leaves a problem. ${existing[0]} will be This.txt only if This.txt exists. That was the point of the test. If This.txt does not exist and TheOther.txt does exist, ${existing[0]} will be TheOther.txt. This is why I would go with just constants in the case statement.
Linux System having all Perl, Python, PHP (and Ruby) installed
From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file
eg
eg
a Shell script run in a case statement call to run a php file, also Perl or/and Python file???
Like
#!/usr/bin/bash
....
....
case $INPUT_STRING... (1 Reply)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
Hey, guys I really need some help with a project.
"Write a shell program that examines the command line... (8 Replies)
Hey, guys I really need some help with a project.
"Write a shell program that examines the command line arguments, counts and collects the number of options. Basically it has to collect and count the arguments that start with a "-" and the one's that don't start with a -
I know I have to use... (2 Replies)
Hello Unix Gurus :
It would be really appreciative if can find a solution for this .
I have records in a file .
I need to Capitalize the records based on condition .
For Example i tried the following Command
COMMAND -->
fgrep "2000YUYU" /export/home/oracle/TST/data.dat | tr '' ''... (12 Replies)
I am writing a script to pull diskspace information from our servers. Here is the script that I wrote:
#!/bin/ksh
for host in `cat /oper/hosts/esc.misc`
do
ssh -q -o ConnectTimeout=10 operator@$host df -h|grep "/dev/" |egrep '8%|9%|100%' | awk '{print H " " "at " $5 " with " $4 "... (1 Reply)
hi all
i'm writing a script and in it i need to prompt the user if the entered value is correct or not ,i wrote the following and its not working ,its executing the script even if i enter Y/N
pls any help is appreciated
echo "\nAre you sure you entered the right Destination Environment? y :... (5 Replies)
I need to have an if statement in a script to run if there are certain processes running. Easiest way I can see to do this is to run a ps and grep the results based on what I am looking for:
$ ps -ef | grep wtrs
---
webtrend 5046 1 0 May 12 ? 0:28 /webtrends/versions/6.1/wtrs_ui... (6 Replies)