Hello. Sorry for the stupid question... Here is the problem. I'm trying to do a script that offers options for backup the root partition in unix sistems.
Here is the code part that i am talking of.
Code:
echo "tar can archive your file using gzip or Bzip2"
echo "gzip : relatively poor compresion ratio and high speed"
echo "Bzip2 : better compression ratio and slow speed"
echo "Choose now : gzip(z) or Bzip2(j)"
read archive_type
if archive_type=z; then
archive_type_0="gz"
fi
if archive_type=j; then
archive_type_0="bz2"
fi
echo "Type the path for backup image(don't type the final slash in the patch)"
echo "Oh, and be sure that your current user level have read/write acces on that path"
read path_save
echo "Enter the name of the backup file"
read name_save
echo "The file will be saved at "$path_save"/"$name_save".tar."$archive_type_0""
sleep 5
tar -cvp"$archive_type"f"$path_save"/"$name_save".tar."$archive_type_0" \
--exclude=$path_save/$name_save \
--exclude=/proc --exclude=/lost+found \
--exclude=/sys \
--exclude=/mnt \
--exclude=/media \
--exclude=/dev /
This is the code part that really bothers me. Leaving the variables without reference call ($) in if statement, seems to work. However, when adding "$"
Code:
if archive_type=z; then
$archive_type_0="gz"
fi
if archive_type=j
then
$archive_type_0="bz2"
fi
the terminal says "/home/editheraven/Desktop/rootsave: 57: j=z: not found" the same for "j" variable. Anyway, the code seems to work without reference call.
Another thing. How can i do a while loop like this
Code:
[pseudocode]
function select
{ read archive_type
if archive_type=j or archive_type=z
break
else call function select
I see that it's a little tricky to pass funtion return value, but i don't see any easy way to verify that the entered key is j or z and if not, to return at "read archive_type".
I know that it sounds a little silly, but it's kinda different from c code, where this can easely be done.
Last edited by vbe; 11-16-2011 at 10:33 AM..
Reason: formatting for ease of reading...
echo "tar can archive your file using gzip or Bzip2"
echo "gzip : relatively poor compresion ratio and high speed"
echo "tar can archive your file using gzip or Bzip2"
echo "gzip : relatively poor compresion ratio and high speed"
echo "Bzip2 : better compression ratio and slow speed"
echo "Choose now : gzip(z) or Bzip2(j)"
read archive_type
if [ "$archive_type" = "z" ]
then
archive_type_0="gz"
fi
if [ "$archive_type" = "j" ]
then
archive_type_0="bz2"
fi
echo "Type the path for backup image(don't type the final slash in the patch)"
echo "Oh, and be sure that your current user level have read/write acces on that path"
read path_save
echo "Enter the name of the backup file"
read name_save
echo "The file will be saved at "$path_save"/"$name_save".tar."$archive_type_0""
sleep 5
tar -cvp"$archive_type"f"$path_save"/"$name_save".tar."$archive_type_0" \
--exclude=$path_save/$name_save \
--exclude=/proc --exclude=/lost+found \
--exclude=/sys \
--exclude=/mnt \
--exclude=/media \
--exclude=/dev /
#!/usr/bin/bash
echo "Choose now : gzip(z) or Bzip2(j)"
read archive_type
if [ "$archive_type" = "z" ]
then
archive_type_0="gz"
fi
if [ "$archive_type" = "j" ]
then
archive_type_0="bz2"
fi
echo archive_type_0 " : " $archive_type_0
#
n12:/home/vbe $ ./004
Choose now : gzip(z) or Bzip2(j)
z
archive_type_0 : gz
I have been reading old posts and trying to come up with a solution for the below: Use a tab-delimited input file to assign
point to variables that are used to update a specific field, Rank. I really couldn't find too much in the way of assigning points
to variable, but made an attempt at an awk... (4 Replies)
Hello,
Below I try to control that the input is good an IP :
#!/bin/bash
cp /home/scripts/choice_interfaces.txt /home/scripts/interfaces.txt
chmod 644 /home/scripts/interfaces.txt
echo -e "Please enter the network informations into the /etc/network/interfaces file, complete them below... (9 Replies)
I was wondering if anyone could provide some assistance. I trying to run an expect script within bash and get the results of a variable called RESULT. I Have tried a few things but none of them have worked. I know that the child process (the expect script) in this instance cannot set a variable... (6 Replies)
Sometimes it is handy to protect long scripts in C++.
The following syntax works fine for simple commands:
#define SHELLSCRIPT1 "\
#/bin/bash \n\
echo \"hello\" \n\
"
int main ()
{
cout <<system(SHELLSCRIPT1);
return 0;
}
Unfortunately for there are problems for:
1d arrays:... (10 Replies)
I have a bash script with some functions as below and am wondering if I can use the variables declared in setup in the other functions and in the rest of the bash script.
setup(){
none=0; low=1; medium=2; high=3; debug=4
var1="red"
var2="fred"
}
create_basemap() {
... (7 Replies)
Hi,
This is probably going to be very simple but i came across something i can't quite explain. Here is the situation: i have a list of files, which i'd like to process one by one (get the size, make some tests, whatever) and generate some statistics using different variables.
Something... (5 Replies)
Ummm can anybody help me with this one?
Its prob quite simple.
I bascially have a file name say J1x2x3x7.dat
Im using the file name as a variable in a bash script. Want I want to do is extract most of the file name and make it a new variable expect with say one of the number now a... (2 Replies)
Hi everyone,
I have added this to my .bash_profile. Whenever I log in and when I type javac I get a error message (java: command not found). Does the order counts?
PATH=$JAVA_HOME/bin:$PATH:$HOME/bin
JAVA_HOME=$JAVA_HOME/usr/local/jdk1.3.1_02
export JAVA_HOME PATH
Thanks
ny (3 Replies)