LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 09-04-2005, 11:18 PM   #1
jgtg32a
Member
 
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

Code:
#!/bin/bash
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" ] 
	then
	clear
	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" ]
		then 
		echo "enter the new ISO's path"
		read ISO
		echo $ISO >> iso.dat
	while [ $ISO -eq $var ]
		do
		# $ISO needs to be redefined as with its coorisponding location
		done
	fi
	mount -t iso9660 -o loop $ISO /mnt/iso 
elif [ $var -eq "2" ] 
	then
	umount /mnt/iso
elif [ $var -eq "3" ]
	then
	exit
else 
	clear
	main
fi
}
clear
main
exit

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

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
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:


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

   *)   mount $file

esac
# break
done
 
Old 09-05-2005, 09:20 PM   #4
jgtg32a
Member
 
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
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

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

Code:
set -- `cat file.dat`

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

or

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

and so on....
and so forth....
 
Old 09-06-2005, 09:38 AM   #6
archtoad6
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.
 
  


Reply



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:10 PM.

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