Chris R.
Chris R.

Reputation: 41

Prompting the user for file names in Unix

I want to write a script which prompts the user for the names of two files, lists the first file on screen and waits for user to press any key before second file is listed on the screen. But I am unsure of how to do this. Could anyone help? I think its something like:

VALID_FILENAME_ONE="Test1"
VALID_FILENAME_TWO="Test2"

echo "Please enter first file name:"
read file_name1

echo "Please enter second file name:"
read file_name2

if [ "$file_name1" == "$VALID_FILENAME_ONE"]; then
    ls -l |  Test1
else
    echo "No further action"
fi

But this does not run correctly. Any help would be much appreciated.

Upvotes: 0

Views: 507

Answers (1)

Andrey Butov
Andrey Butov

Reputation: 2279

In the following line:

if [ "$file_name1" == "$VALID_FILENAME_ONE"]; then

... add a space between "$VALID_FILENAME_ONE" and the closing square bracket, like this:

if [ "$file_name1" == "$VALID_FILENAME_ONE" ]; then

Otherwise, bash can't parse your syntax.

Upvotes: 1

Related Questions