Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shell script to find file name from its path

Tags:

Hello i want a simple shell script that find the name of the file from a given path of the file. like

$path = "/var/www/html/test.php";

then i want to get value "test" in some variable. Also only .php files are present.I am using bash shell. Thanks

like image 339
ayush Avatar asked Jan 10 '11 09:01

ayush


1 Answers

Try:

path="/var/www/html/test.php"
name=$(basename "$path" ".php")
echo "$name"

The quotes are only there to prevent problems when $path contains spaces.

like image 171
Aaron Digulla Avatar answered Sep 19 '22 13:09

Aaron Digulla