-   Linux - Software (
-   -   bash script: to truncate filename (

casualzone 04-21-2011 11:51 PM

bash script: to truncate filename
try to write a simple bash script

If the input $1 is a "myfilename.txt",
How could I store the "myfilename" as my another variable instead of "myfilename.txt". I want the script to make a new directory name as myfilename

anomie 04-22-2011 12:01 AM

I believe there is bash(1)-fu to solve this sort of thing, but I'm pretty fond of g/awk(1):

_name=$(echo ${1} | awk -F'.' '{print $1}')

crts 04-22-2011 06:25 AM

Here is a pure bash solution:

If your name has several dots in it like

then it will only delete the last part like

If you want the output to be just

then you can use


casualzone 05-24-2011 10:01 PM

How about for the csh case?

All times are GMT -5. The time now is 02:11 PM.