user2329110
user2329110

Reputation:

Write a script that takes exactly one argument, a directory name

Write a script that takes exactly one argument, a directory name. The script should print that argument back to standard output. Make sure the script generates a usage message if needed and that it handles errors with a message.

I write code, how i understand. Am i understand correctly this question? Maybe there are other versions how find directory.

#!/bin/bash

echo "Enter fail name:"
read str

find "$str" 2>/dev/null

sa=$?

if [ "$sa" = '0' ]    
then    
   echo "$str"    
else
   echo "Error"
fi

Upvotes: 1

Views: 3536

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201439

Your script doesn't appear to be using an argument. In bash the first one ($0 is your script) would be $1 and something like,

#!/bin/bash

if [ "$1" == "" ]; then
  echo "$0: Please provide a directory name"
  exit 1
fi
if [ ! -d "$1" ]; then
  echo "$0: $1 is not a directory name"
  exit 1
fi
echo "$1"

Upvotes: 1

Related Questions