not script prompting but,.............

Hi,
I am writig this script and usually I have prompts like:
echo "Enter file name: "
read "$filename"

So later when I want verify the name to something I can:
if [ "$filename" = "penski" ]
then
echo "Hello $filename"

Anyways how is this done without prompting for example:
I have a script that manages files, but when running the program you type this at the command line:

file mynewfile.txt

where mynewfile is a file in my dir and file is the name of the script:
Becuase I need my script to say whether this is a valid file in my dir.
Thanks,

theA

Arguments to shell scripts take the form $0, $1, $2, etc. where either $0 or $1 (forgot) is the name of the script and the next one is the next argument etc. so:

file hello.txt

$0 (or $1 ... you need to check) is "file"
$1 (or $2 ... you need to check) is "hello.txt"

Those shell variables are outlined in the shell books you own Astudent, if memory serves me tonight.

Neo - I know that part - that's what I'm using for my other "if" statements.
I just don't know how to have it recognize if the file is in my dir.

Usually I prompt so when you echo the question you have
read $filename

if [ "$#" = "$filename" ]
,....

But thanks anyways,
But I am not allowed to prompt the user,
Here is how it should look

file look

  • that file isn't in your directory

file mynewfile
-output is then revealed -

I hope this helps!

theA

Hi!

If I got you correctly , you don't look for the command line argument parsing ($0 is for the command name itself and $1 the first param - checked in "Unix in a Nutshell")

What you look for is maybe testing if a filename exist in the current direcotry ?

To do that you just use on ksh:

if [ ! -e "$1" ];
then
echo this file does not exist
fi

next time please specify which shell you are using sh/ksh/csh...

Hezki