Help with Shell script

This is a line in the shell script i am writing. So the $1 argument is the path to the tar file that i pass, for example "./UnixScript.sh /var/tmp/asirohi/j564redist.tar.gz"

I want to store "/var/tmp/asirohi" in a variable, this value can change. it is one directory up from the first argument passed. If is argument is:-
/var/tmp/asirohi/j564redist.tar.gz then /var/tmp/asirohi
/net/lockbox/vol/homes/j564redist.tar.gz then /net/lockbox/vol/homes/

Thanks
Aditya

#!/bin/sh


PATH_TO_TAR=`echo $1`
echo $PATH_TO_TAR
PATH_TO_TAR="${1%/*}"
echo $PATH_TO_TAR

Hope below example will be helpful

$ myvar=/net/lockbox/vol/homes/j564redist.tar.gz
$ dirname $myvar
/net/lockbox/vol/homes

Regards,

Jith

1 Like