1758581 Members
1869 Online
108872 Solutions
New Discussion юеВ

Re: Variable in script

 
SOLVED
Go to solution
Patrick Wallek
Honored Contributor

Variable in script

Ok, I know I should know how to do this, but apparently I'm brain dead today......

I have a variable in a script like: VAR=/home/directory/filename

How do I strip off just filename from $VAR so that VAR1=filename?
3 REPLIES 3
James A. Donovan
Honored Contributor
Solution

Re: Variable in script

# VAR1=`basename $VAR`
Remember, wherever you go, there you are...
Patrick Wallek
Honored Contributor

Re: Variable in script

Thanks Jim. I knew it was something simple and I should have known what it was.
Rodney Hills
Honored Contributor

Re: Variable in script

You can also use
${VAR##*/}

This saves a fork of a another process
There be dragons...