Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Linux and Unix
Tag Cloud
access audio black screen blue screen boot bsod connection crash dell desktop drivers dvd email error excel excel 2003 firefox hard drive hardware hdmi hijackthis internet keyboard laptop malware monitor motherboard network networking outlook problem recovery router safe mode screen slow sound spyware tdlwsp.dll trojan vba video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
Bash scripting help

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
tsunam's Avatar
Senior Member with 1,246 posts.
 
Join Date: Sep 2003
Experience: Linux~su
13-Sep-2004, 06:16 PM #1
Bash scripting help
Alright, here's one for you all.

I have a script that currently requires a user to do a

./program.sh file.img /dev/sda

to get it to run properly.

I've decided that since more people are going to be creating the applications onto the flash cards that I need to modify it so that instead of having to type that in and be bugged about the proper format that I'll just do a few prompts to tell them what they need to put in.

Basically what I have so far is
echo "what is the image you wish to copy? filename.img"
read $1

dp=1
while [ $dp != "0" ] do
dd if=$2 of=/dev/null bs=512 count=1
dp=$?
done

sync

echo ... Copied $1 to $2

of course all the $2 can either be a prompt or I can just set it to what it will be since no one will be modifying what /dev/sda its on or where its mounted to.

However the problem i'm having is that when it goes to the read $1 and it gives the blank space to type...it doesn't allow for tab completition to follow. That's something I need to be able to do since People don't want to Write down a 40 character named .img. -_- making modifications for windows people bleh! (is it possible to still have a tab completition? if not well maybe a ./program.sh and it automatically does a --help file that would explain how to use it?)

any help would be appreciated. (yes this is a shortened form of the actual exact program but gives a idea of what I'm doing.)
__________________
Gentoo Developer, and 64bit os user

"In feeding Mother Nature, you are fed in return" - Tsunam (2005). Concerning water conservation, and raising water tables.

Last edited by tsunam : 13-Sep-2004 06:25 PM.
Squashman's Avatar
Distinguished Member with 14,983 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
14-Sep-2004, 10:52 PM #2
I don't think you can do Tab completion but you can have them select a file from a Dialog box if you have Dialog installed on your system. I just started using Dialog Boxes for many of my bash scripts. It is much more user friendly for the technically impaired.

I could show you a few examples of how to do it right now, but my server is in the middle of a RaidHotAdd.

There is a Box option for Dialog that will display the listing of a Directory and let the user chose which file they want to select with the arrow keys.

Let me tell you this. Once you start using Dialog Boxes in your Bash Scripts, you may never go back to just text. I love them.
__________________
I hate asking the same question twice!
How to ask questions the smart way!
Microsoft MVP - User Desktop Experience
tsunam's Avatar
Senior Member with 1,246 posts.
 
Join Date: Sep 2003
Experience: Linux~su
15-Sep-2004, 02:36 AM #3
Oh! you'll have to show me LwdSquashman after the RaidHotAdd. That sounds too cool
Squashman's Avatar
Distinguished Member with 14,983 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
17-Sep-2004, 10:22 AM #4
Your other option would be to do a ls *.img before you ask them what file they want to chose.

They could then use there mouse to highlight the file they want to chose and then they can just right click in the window and it will paste the filename into the script. This seems to work fine for me in putty.
__________________
I hate asking the same question twice!
How to ask questions the smart way!
Microsoft MVP - User Desktop Experience
Squashman's Avatar
Distinguished Member with 14,983 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
17-Sep-2004, 10:46 AM #5
Your other option is to do a dialog box. But you have to have dialog installed on your system.

Code:
#!/bin/bash

FILE=`dialog --backtitle "Tsunam's Script" --stdout --nocancel --title "Please choose a file" --fselect /bin/ 14 48`

clear
echo $FILE
You use the arrow keys or tab to navigate. Use the spacebar to select and type enter to take the selection.
Attached Thumbnails
Bash scripting help-dialog.jpg  
tsunam's Avatar
Senior Member with 1,246 posts.
 
Join Date: Sep 2003
Experience: Linux~su
17-Sep-2004, 08:25 PM #6
Damn that is sweet! excuse the language...I can see why you say I will never go back to any other method. Woo you are a lifesavior to the windows people at my office.
Squashman's Avatar
Distinguished Member with 14,983 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
17-Sep-2004, 10:24 PM #7
There is alot of things you can do with Dialog Boxes. They are pretty amazing. Do a man on dialog and look at all the Box Options. You can also change the color of the text.

Let me know if you need any help with them. I have gotten pretty fluent with them.
__________________
I hate asking the same question twice!
How to ask questions the smart way!
Microsoft MVP - User Desktop Experience
tsunam's Avatar
Senior Member with 1,246 posts.
 
Join Date: Sep 2003
Experience: Linux~su
18-Sep-2004, 05:15 AM #8
tested it out on my machine, worked beautifully...course the work one...doesn't have display or any of the imagemagick suite of stuff...why would it =/. Figure I'll either a upgrade the machine to fedora, and install it at that point...or do it another way. *grumbles*
tsunam's Avatar
Senior Member with 1,246 posts.
 
Join Date: Sep 2003
Experience: Linux~su
29-Sep-2004, 07:50 PM #9
something is off somewhere

Code:
#!/bin/sh
X='dialog --backtitle "Video Reel Game Image Copy" --stdout --nocancel --title "Select File" --fselect /tmp 14 48'
echo $X
appears to be correct however it fails utterly. I'm not seeing anything wrong with the code in the string.

Vi is giving me this though:
X='dialog --backtitle "Video Reel Game Image Copy" --stdout --nocancel --title "Select File" --fselect /tmp 14 48'

Whereas vi with just the dialog gives:
dialog--backtitle"Video Reel Game Image Copy"--stdout --nocancel --title"Select File"--fselect/tmp 14 48

For some reason its not liking being a string variable...If its just run by itself its fine but doesn't like it otherwise. The former will run but doesn't do a display and thus doesn't get a variable. The latter runs like display should but doesn't get a variable. I've tweeked it various ways and went looking at strings and I am utterly confused as to why its not accepting the display as a variable string
__________________
Gentoo Developer, and 64bit os user

"In feeding Mother Nature, you are fed in return" - Tsunam (2005). Concerning water conservation, and raising water tables.
Closed Thread Bookmark and Share

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 05:01 AM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.