Results 1 to 6 of 6
  1. #1


    Member Since
    Jul 16, 2017
    Posts
    2
    Terminal: line of code to ask user to select name from a list?
    Hi all,
    In my script I use the ls command to display the list of files in the directory. I then want the user to choose and input a single file name from the list (using the read command). If they enter a name not listed above I want the terminal to ask them to retype. The files in the directory are not always going to be the same every time the script is run, so the script will have to somehow compare the user input to all files in that directory at that current time. Can I compare input to ls somehow?

    Thank you in advance
    (P.s. I'm new to this )

  2. #2

    Raz0rEdge's Avatar
    Member Since
    Jul 17, 2009
    Location
    MA
    Posts
    9,495
    Specs:
    27" i7 iMac, 15" Macbook Pro TB, 13" Macbook Air, iPhone 6S, iPod Nano 7th Gen
    First, what language are you typing the script in? The ls command is just going to list the contents of a directory in various ways, so for any comparison, you'll have to keep track of the files in an array or something and then compare that against subsequent ls commands.
    --
    Regards
    ...Ashwin



    Be sure to read the Community Guidelines | The more information you provide, the better answers you get, remember GIGO.

  3. #3


    Member Since
    Jul 16, 2017
    Posts
    2
    I'm making a simple bash script, i'm writing it in text editor and then using 'chmod 700' to turn it into an exe file. Oh i see, how do i go about doing that? I don't exactly know what to search to find a relevant guide, perhaps you could point me in the right direction

  4. #4

    Raz0rEdge's Avatar
    Member Since
    Jul 17, 2009
    Location
    MA
    Posts
    9,495
    Specs:
    27" i7 iMac, 15" Macbook Pro TB, 13" Macbook Air, iPhone 6S, iPod Nano 7th Gen
    I wouldn't suggest BASH as the language, you're better of with something like Python which has access to many packages that will aid you as your script gets more complicated.

    However, if you want to stick with BASH, then checkout BASH Beginners Guide which explains the basics..

    Beyond that, how you do what you need to do depends on how good you are at programming..
    --
    Regards
    ...Ashwin



    Be sure to read the Community Guidelines | The more information you provide, the better answers you get, remember GIGO.

  5. #5

    cradom's Avatar
    Member Since
    Feb 14, 2004
    Location
    Groves, Texas
    Posts
    4,698
    Specs:
    21in. iMac 10.11 --- HP Linux Mint 18
    I agree with Ashwin, probably better off using something like Python. However if you insist on using Bash...
    http://www.bash.academy/
    https://www.blockloop.io/mastering-bash-and-terminal
    https://github.com/Idnan/bash-guide
    Any priest or shaman must be presumed guilty until proved innocent.

  6. #6

    Mark FX's Avatar
    Member Since
    Aug 13, 2011
    Location
    West Sussex, UK
    Posts
    200
    You haven't stated what you want to do with any selected files.

    But I would use a simple AppleScript to select the Folder and Files to process.

    After all, that's what AppleScript was designed for.

    Regards Mark

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. writing terminal code
    By lherriman in forum OS X - Operating System
    Replies: 20
    Last Post: 11-20-2011, 11:17 PM
  2. Dropdown list in subject line, Mac mail?
    By EdH in forum OS X - Apps and Games
    Replies: 2
    Last Post: 01-29-2010, 09:25 AM
  3. open new terminal from command line
    By drjimmy42 in forum OS X - Operating System
    Replies: 0
    Last Post: 03-02-2009, 11:06 PM
  4. I need help with this command line using Terminal app
    By SniperCrim in forum OS X - Development and Darwin
    Replies: 1
    Last Post: 09-07-2007, 11:26 PM
  5. File type code from the command line
    By smook1980 in forum OS X - Development and Darwin
    Replies: 1
    Last Post: 02-17-2004, 11:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •