Results 1 to 6 of 6
Hi folks,
I have a bash script with following line running at its end
.........
......
# Remove ISO File...
rm -i $ISO_File
- End of Script -
The script ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-01-2004 #1Linux Guru
- Join Date
- Sep 2004
- Posts
- 1,712
Bash script - to save and run a command at the end
Hi folks,
I have a bash script with following line running at its end
.........
......
# Remove ISO File...
rm -i $ISO_File
- End of Script -
The script is working without problem.
Now I expect to set this line as argument, i.e. removing it leaving only there;
........
.......
# Remove ISO File ...
(Empty)
- End of Script -
Somewhere at the beginning of the Script add following lines
.......
read -p "Remove ISO File <yes|no>:"
if [ "$REPLY" = "yes" ]; then
echo "rm $ISO_File"
read
etc.
I have no idea how to get the line "rm $ISO_File" saved after
# Remove ISO File...
and run at the end of the script
Please advise. TIA
B.R.
satimis
- 11-01-2004 #2
Move the comment?

I'm not sure I understand what exactly you are trying to accomplish. Where is the script getting the ISO name? What are you trying to accomplish? What does the rest of the script do?
"Time is an illusion. Lunchtime, doubly so."
~Douglas Adams, The Hitchhiker's Guide to the Galaxy
- 11-01-2004 #3Linux Guru
- Join Date
- Sep 2004
- Posts
- 1,712
Hi sarumont,
Hereinunder is the full scriptI'm not sure I understand what exactly you are trying to accomplish. Where is the script getting the ISO name? What are you trying to accomplish? What does the rest of the script do?
Name of script = cdmaker#!/bin/bash
#Set directory path...
user=$(whoami)
now=$(date +%Y.%m.%d.%R)
ISO_File="/tmp/satimis/image_${use* r}_${now}.iso"
Default=$1
#Temporary file to store the resulting mkisofs command
CmdFile_1=/tmp/satimis/.TmpBurnCD$* $
list=""
CopyDir(){
name=$1
dir=$2
if [ "$Default" = "" ];then
list="$list \"$name=$dir\""
else
if [ "$Default" = "yes" ];then
list="$list \"$name=$dir\""
fi
fi
}
CopyDir "/Document/" "/home/satimis/Document/"
CopyDir "/Photo/" "/home/satimis/Photo/"
# Loop to get other directories...
echo "Enter directories to burn. Leave blank to end list"
entry="empty"
until [ -z $entry ]; do
echo -n "Enter a directory (eg: /Photo/=/home/satimis/Photo): "
read entry
if [ "$entry" != "" ]; then
# OR USE if [ z$entry != "z" ]; then
list="$list \"$entry\""
fi
done
# If at least one directory has been entered....
if [ "$list" != "" ];then
#Construct the mkisofs command...
echo "/usr/bin/mkisofs -R -l -o $ISO_File -hide-rr-moved -graft-points \
$list" > "$CmdFile_1"
#Now create the image
/bin/sh "$CmdFile_1"
#Remove the temporary file
rm -f "$CmdFile_1"
#Temporary file to run cdrecord command
CmdFile_2=/tmp/satimis/.TmpCdrecor* d$$
su -c "cdrecord dev=ATA:1,0,0 -v -eject $ISO_File"
#Now run cdrecord
/bin/sh "$CmdFile_2"
#Remove the temporary file
rm -f "$CmdFile_2"
fi
#Remove ISO File...
rm -i $ISO_File
The script copies files from preset and input directories, burning them on CD and remove the ISO File finally. Before removing the ISO File, option prompts to keep it or remove it.
Now I want to make this option to be selected at the beginning of the script but the command runs at end of the script after CD burnt.
may achieve my goal. But "rm $ISO_File" will be added permanently to the script.Code:...... read -p "Remove ISO File <yes|no>:" if [ "$REPLY" = "yes" ]; then echo "rm $ISO_File" >> cdmaker
I'm now looking for a solution adding "rm $ISO_File" temporarily at end of the script only on being selected.
B.R.
satimis
- 11-02-2004 #4
Just put a prompt at the beginning of the script to ask to keep the ISO. Then at the end, check the value of that variable (choose a name that you're not using elsewhere) and deal with it accordingly.
Code:readline -p "Delete ISO when done (yes/no)? " REPLY #Input integrity checking ...rest of script... if[ $REPLY = yes ]; then rm $ISO_File fi
"Time is an illusion. Lunchtime, doubly so."
~Douglas Adams, The Hitchhiker's Guide to the Galaxy
- 11-02-2004 #5Linux Guru
- Join Date
- Sep 2004
- Posts
- 1,712
Hi sarumont,
Tks for your advice.
Directory for keeping ISO file already existingJust put a prompt at the beginning of the script to ask to keep the ISO. Then at the end, check the value of that variable (choose a name that you're not using elsewhere) and deal with it accordingly.
.......
/tmp/satimis/
Test performed as follow;
"readline -p "Delete ISO when done <yes|no>?" REPLY" won't ask for input. I changed it as "read -p "Delete ISO when done <yes|no>?" REPLY" Then if asked for input
Script:-Printout :-Code:#!/bin/bash set -x #Set directory path... user=$(whoami) now=$(date +%Y.%m.%d.%R) ISO_File="/tmp/satimis/image_${user}_${now}.iso" # Remove ISO File... read -p "Delete ISO when done <yes|no>?" REPLY #Input integrity checking ..... # My script ..... # Remove ISO File... if [ $REPLY = yes ]; then rm $ISO_File fiThe script asked for input <yes|no>? at the begining. It asked again at the end, twice/2nd time,Code:....... + rm -i /tmp/satimis/image_satimis_2004.11.02.16:13.iso rm: remove regular file `/tmp/satimis/image_satimis_2004.11.02.16:13.iso'? y + '[' '' = yes ']'
I think it is the
rm
is often aliased to
rm -i
"rm' removed the ISO file not your additional script
B.R.
satimiks
- 11-02-2004 #6
Oops...forgot that it was read and not readline.

As to the rm thing...bypass the alias using:
Code:command rm $ISO_File
"Time is an illusion. Lunchtime, doubly so."
~Douglas Adams, The Hitchhiker's Guide to the Galaxy


Reply With Quote
