1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Bash scripting help

Discussion in 'Linux and Unix' started by tsunam, Sep 13, 2004.

Thread Status:
Not open for further replies.
Advertisement
  1. tsunam

    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.)
     
  2. Squashman

    Squashman 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.
     
  3. tsunam

    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
     
  4. Squashman

    Squashman 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.
     
  5. Squashman

    Squashman 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.
     

    Attached Files:

  6. tsunam

    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.
     
  7. Squashman

    Squashman 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.
     
  8. tsunam

    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*
     
  9. tsunam

    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
     
  10. Sponsor

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 733,556 other people just like you!

Loading...
Similar Threads - Bash scripting help
  1. binny18
    Replies:
    10
    Views:
    397
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/273588

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice