-3

I would like to store the path of a file typed by the user in a variable and then use it

enter image description here

jww
  • 83,594
  • 69
  • 338
  • 732
  • See [why doesn't cd work in a bash shell script](https://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script) – Mark Plotnick Jul 21 '17 at 19:21

2 Answers2

0
#!/bin/bash 

echo "read es: " $1 
dirname $1

command line is ./bashName.sh path

-1

Use dirname to get just path for any "file".

Example:

$ read -p "Please type file full path: " myVar
Please type file full path: /tmp/bla/bla/file
$ dirname "${myVar}"
/tmp/bla/bla
Azize
  • 2,386
  • 1
  • 14
  • 28