Bash scripting help

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

tsunam

Thread Starter
Joined
Sep 14, 2003
Messages
1,240
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.)
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
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.
 

tsunam

Thread Starter
Joined
Sep 14, 2003
Messages
1,240
Oh! you'll have to show me LwdSquashman after the RaidHotAdd. That sounds too cool
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
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.
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
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.
 

Attachments

tsunam

Thread Starter
Joined
Sep 14, 2003
Messages
1,240
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

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
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.
 

tsunam

Thread Starter
Joined
Sep 14, 2003
Messages
1,240
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

Thread Starter
Joined
Sep 14, 2003
Messages
1,240
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
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top