Results 1 to 3 of 3
I have this backup script that works well,
#/bin/bash
finished="false"
while [ "$finished" = "false" ]
do
clear
#chose the path to be backedup
echo "Enter the path of the ...
- 11-19-2007 #1Just Joined!
- Join Date
- Nov 2007
- Posts
- 9
Backup Script
I have this backup script that works well,
#/bin/bash
finished="false"
while [ "$finished" = "false" ]
do
clear
#chose the path to be backedup
echo "Enter the path of the directory to be backed up"
read backup_location
#chose the path of the destination
echo "Enter the path of where you want the backup saved"
read destination_location
#informing us if the backup was successful or not
tar -cvf $destination_location $backup_location
code=$?
if [ $code -eq 0 ]
then
echo "Backup successfull"
else
echo "Backup did not work press any key to run again or n to exit"
fi
#the loop to either exit or restart the program
read resp
if [ "$resp" = "n" ]
then
finished="true"
fi
done
echo "exiting backup.sh"
But i need to modify it so that to run it you just have to type,
./backup.sh <directory to be backed up> <directory to save to>
then the script automaticly does evereythong so i do not have to propmt users once the command ahs been entered but i have no idea how to split the two variables adn take them from after the initial command and use them in the script.
How can i split the variables and get teh script to run with one simple command
thanks for your help i am new to scripting
- 11-19-2007 #2
Hi and Welcome to the LinuxForums !

You can use $#, $*, $1, $2, $3.... etc to access parameters passed with script name.
Here is an example:
Save it as test.sh and execute thisCode:#!/bin/bash # Its a test script : test.sh echo "First Parameter : \$1 = $1" echo "Second parameter : \$2 = $2" echo "Total passed parameters : \$# = $#" echo " All parameters : \$* = $*" exit 0
This is a test script are parameters passed to script test.sh.Code:chmod +x test.sh ./test.sh This is a test script
Check linuxcommand.org too.
HTH !It is amazing what you can accomplish if you do not care who gets the credit.
New Users: Read This First
- 11-19-2007 #3Just Joined!
- Join Date
- Nov 2007
- Posts
- 9
Thanks a lot it has helped heaps


Reply With Quote