You are not logged in.
Is it possible to make a variable equal another variable..but remove something from the second variable first?
example:
Like $*=/home/user/Desktop/test.jpg
I want VARIABLE=$* - /test.jpg
So then I can do something like this in my script
cd $VARIABLE
Anyway I can do that..?
Last edited by whaevr (2009-01-19 00:58:53)
Offline
You can cut your variable before using it with cd.
Something like:
[pts/0][shaika-dzari]>VAR='/home/shaika-dzari/haruhi.txt'
[pts/0][shaika-dzari]>echo $VAR | cut -d/ -f1,2,3;
/home/shaika-dzari
[pts/0][shaika-dzari]>
BUT, I'm not really great in bash. I'm sure there are others and betters solutions.
Maybe awk or sed...
Shaika-Dzari
http://www.4nakama.net
Offline
In general, yes. And in your specific case:
$ i=/home/user/Desktop/test.jpg
$ j=$(dirname $i)
$ echo $j
/home/user/Desktop
Offline
Something like this?
> var1=/home/user/Desktop/test.jpg; var2=${var1%/*}; echo $var2
/home/user/Desktop
See man bash -- "Parameter Expansion" section for more.
EDIT: small fix
Last edited by fwojciec (2009-01-19 00:04:27)
Offline
Alright thanks guys!
Shaika-Dzari yours would work for that specific directory but if I were to use the same script and need it to apply to "/home/user/Desktop/folder/test.jpg" I would need to cut more off it, so it wouldn't work.
tam1138 thanks you gave me what I needed!
fwojciec I didn't try yours..I stopped when tam's worked and yours looks complicated lol
Heres the script I made its for use with the nautilus-actions package.
#!/bin/sh
WOO=$(dirname $*)
NAME="$(zenity --entry --title "Enter Stream" --text "Enter stream number and name to save as")"
cd $WOO
mkvextract tracks $* $NAME | zenity --progress --text="Extracting stream(s)" --pulsate
I do a lot of video editing and was getting tired of doing that in command line over and over...:lol:
Last edited by whaevr (2009-01-19 00:12:10)
Offline
You don't want $* there. That's a list of ALL command-line arguments (and dirname won't behave how you expect/want it to). $1 is the first argument, $2 is the second, etc. Even better, at the top, use FILENAME=$1 to put it into a variable with a meaningful name, so that a) it's clear to a user what the command-line arguments mean and b) it's easier to debug later---because sorting out $FILENAME is way easier than $1, let me tell you.
Offline