1

Iam making a program with a fast menu in linux shell.

A option is to edit or to change directory.

I need to see if it is a directory or a file, because i need to use vim for a file and cd for a directory.

Thank you for reading/helping

Ebbez
  • 344
  • 1
  • 2
  • 13

1 Answers1

0
echo "Input a file: "
IFS= read -r file

if test -f "$file"
then
  echo "$file is a regular file"
elif test -d "$file"
  echo "$file is a directory"
else
  echo "It's something else, like a socket, fifo or device."
fi

Also, see this post if you cd but still find yourself in the same directory after your script exits.

Community
  • 1
  • 1
that other guy
  • 116,971
  • 11
  • 170
  • 194