When I pass the full path of the file to the shell as an argument, I want to change the name while using the original file name Example: Arguments → /home/desk/a.txt Output → /home/desk/bc_a.txt
a=/home/desk/a.txt
echo $(dirname ${a})/bc_$(basename ${a})
/home/desk/bc_a.txt
The dirname command extracts the directory part of the argument basename extracts the file name part Since it is possible to determine the extraction conditions in detail, it is necessary to investigate if necessary. (Extract without extension, etc.)
Recommended Posts