Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-04-2005, 11:18 PM   #1
Registered: Feb 2005
Posts: 53

Rep: Reputation: 15
Bash Scripting help

I have some experence coding in C++, Java but that was a HS class a few years ago, but we never did any work with external files so thats where I need help

declare var ISO
function main
echo "Welcome to ISO tools"
echo ""
echo "1) Mount an Image"
echo "2) Unmount Image"
echo "3) Quit"
read var
if [ $var -eq "1" ] 
	umount /mnt/iso #I got some wierd message about it being mounted multiple times so I added this
	echo "Select an ISO to mount" 
	#need to display the all the ISO locations and have them numbered so the number can be selected 
	read ISO
	if [ $ISO -eq "0" ]
		echo "enter the new ISO's path"
		read ISO
		echo $ISO >> iso.dat
	while [ $ISO -eq $var ]
		# $ISO needs to be redefined as with its coorisponding location
	mount -t iso9660 -o loop $ISO /mnt/iso 
elif [ $var -eq "2" ] 
	umount /mnt/iso
elif [ $var -eq "3" ]

Last edited by jgtg32a; 09-04-2005 at 11:24 PM.
Old 09-05-2005, 12:46 AM   #2
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 680Reputation: 680Reputation: 680Reputation: 680Reputation: 680Reputation: 680
I don't know what you are trying to do with the "echo $ISO >> iso.dat" line.

However, for the part displaying and selecting iso file in a directory, try the select command:
select isofile in *.iso
Old 09-05-2005, 04:52 AM   #3
Senior Member
Registered: Mar 2004
Location: england
Distribution: NetBSD, Void, Debian, Mint, Ubuntu, Puppy, Raspbian
Posts: 3,487

Rep: Reputation: 233Reputation: 233Reputation: 233
as jschiwal said.

the select command will print numbered choices for you automatically.
Endlessly until you break
And you can use case which looks a bit neater than nested if statements
and uses globbing.

something like:

select file in  QUIT *.iso ;do
case $file in
   QUIT) break 2

   *)   mount $file

# break
Old 09-05-2005, 09:20 PM   #4
Registered: Feb 2005
Posts: 53

Original Poster
Rep: Reputation: 15
Well this will work

but I was hoping that I wouldn't have to hardcode all the iso locations, I was hoping to access them from a .dat so when I wanted to add a new ISO location I didn't have to modify the source code.
Old 09-06-2005, 08:33 AM   #5
Senior Member
Registered: Mar 2004
Location: england
Distribution: NetBSD, Void, Debian, Mint, Ubuntu, Puppy, Raspbian
Posts: 3,487

Rep: Reputation: 233Reputation: 233Reputation: 233
this is *nix
you don't have to do anything!

set -- `cat file.dat`

select file in $*
Is one way to skin this particular cat.


$LOCATIONS=`cat datfile`
select file in $LOCATIONS

and so on....
and so forth....
Old 09-06-2005, 09:38 AM   #6
Senior Member
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
0. Concur w/ billy.
Some other tips / suggestions.[list=1][*]What are you trying to do w/ declare var ISO?[*]function main is easier as main (), but then you may like to see "function".[*]Indent inside the function.[*]Keep the tab stops to 2, 3, or 4.[*]Fold the (expletive deleted) comment lines to fit on an 80 column screen.[/list=1]
Rick's 3 laws of programming: © f.a.archibald.iii 2003-2005
Clarity, Brevity, Generality.

The wide tab stops & esp. the long comment lines keep people from easily reading & grasping your code. Especially you, if you come back to it in, say, 6 months time. As a side effect it hoses the display of the entire thread on Konqueror -- it forces horizontal scrolling == PITA.

If you have any doubt about the idea of your future self as one of your most important readers, track down & read ESR's (Eric Raymond) piece on why he likes Python better than Perl.

Last edited by archtoad6; 09-06-2005 at 09:41 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash scripting pete1234 Programming 1 09-27-2005 01:48 AM
bash scripting.. kurrupt Programming 3 09-21-2005 12:07 AM
BASH If-then-else Scripting Help xianzai Programming 4 10-29-2004 04:09 AM
Bash scripting JonCooperUK Programming 3 03-04-2004 08:55 PM
Bash scripting kbeaver Programming 5 07-18-2003 08:35 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:58 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration