You are not logged in.
Dear Fellow Archies!
I use the command
rar a -w<working_folder> -m5 -v<max_volume_size> <archive_name> <target_file_or_folder>
whenever I need to make a multiarchive rar file, because I have not yet found a GUI archive manager that does this.
So, I've decided to write a simple bash script to make things easier.
Here's the script:
#!/bin/bash
echo Please, enter the full path to the target file or folder [without the target itself]!
read PATH
echo Please, enter the target filename [with extension] or folder name!
read TARGET
echo Please, enter the desired archive name [without extension]!
read DESTINATION
echo Please, enter the desired volume size in KB!
read SIZE
rar a -w$PATH -m5 -v$SIZE $DESTINATION $TARGET
Executing the last line of the code in terminal works without any hassle. When I run this entire script however, it doesn't.
What needs to be changed for the script to work?
RAR man page is HERE - CLICK, in case someone needs to take a look at something.
Thank you and thank you,
UFOKatarn
Last edited by UFOKatarn (2012-05-03 07:38:28)
Offline
PATH is a special variable in shell scripting. The value of PATH tells the shell which directories to search for executables when running an external command such as rar.
Offline
Juster: Thank you for the answer. I renamed "PATH" and "$PATH" to "LOCATION" and "$LOCATION", but it still didn't work. So my guess is that after "read" and after "$", what is physically written doesn't matter, even if the text following these two commands is normally used as a command on it's own.
My guess would be that the problem lies in those shell tricks where the process instance "escapes" from she shell and is executed on its own, without the correct path where you want the script to run.
Any thoughts?
Thanks again,
UFOKatarn
Offline
Why do you think it doesn't work? What do you consider working? Please post the bad output of the script and maybe even the good output of the command. Run the script with bash -x or add -x to the shebang line to see what is being run.
Offline
Make sure to quote the location variable, since read picks up on spaces, but bash expansion does not. First space it encounters, if bash is concerned, is the end of your variable's value.
Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy
Offline
Wow, I didn't know about the "-x" switch!
And by "it doesn't work", I meant that no archive file is produced by the script.
Thank you both!
So, after running the "multirar" script, I found out that the "rar" command is not recognized (see last line of output). How? Why?
bash -x multirar
+ echo Please, enter the full path to the target file or folder '[without' the target 'itself]!'
Please, enter the full path to the target file or folder [without the target itself]!
+ read LOCATION
/home/ufokatarn/
+ echo Please, enter the target filename '[with' 'extension]' or folder 'name!'
Please, enter the target filename [with extension] or folder name!
+ read TARGET
testfile.pdf
+ echo Please, enter the desired archive name '[without' 'extension]!'
Please, enter the desired archive name [without extension]!
+ read DESTINATION
testarchive
+ echo Please, enter the desired volume size in 'KB!'
Please, enter the desired volume size in KB!
+ read SIZE
100000
+ rar a -w/home/ufokatarn/ -m5 -v100000 testarchive testfile.pdf
multirar: line 10: rar: command not found
Any ideas?
Last edited by UFOKatarn (2012-05-02 19:42:14)
Offline
My guess is your original program (i.e. with the read PATH) overwrote the original $PATH variable set by the shell by default. Try opening a new terminal or if that doesn't work, re-login.
Offline
rar is not being located in the script's currently active PATH. Check to make sure PATH is set properly in the script (add a line of: echo "$PATH"). If not, either add the directory containing rar to PATH or move rar to a standard location. Working from the other direction, check to see if the successful call to rar has a different PATH than your script.
If rar is in the current directory, then . (a period) must be in your PATH in order for the shell to search the current directory for commands. An empty entry means the same thing as a period.
Offline
Done! Working!
Geniuz: Logout-login did it. How simple.
Juster: I added "echo $PATH" to the script and ran it with "bash -x". And the output was the same as after the logout-login. Here it is, in case you are curious.
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin/core_perl:/opt/qt/bin
Thank you all for your help guys :bow:.
-------
OFFTOPIC:
All who intend to use Xfce launchers to run bash scripts: There are two options in the settings for each launcher: "Command" and "Working Directory". And when I had "Working Directory" filled with "/home/username/", the script didn't work. It worked perfectly after I blanked out the "Working Directory" option. Just so you know, in case someone doesn't .
This has never happened to be before, but still, I guess it is better to do it with blank "Working Directory" and entering the entire path into the script in the "Command" field. It might be that Xfce launchers always stick to the "Working Directory", even though a script might tell them otherwise.
Last edited by UFOKatarn (2012-05-03 07:38:05)
Offline