How to get ls in "select * in *?How can I create a select menu in a shell script?Unity Icon for a bash ran programHow can I get Subliminal to work and then integrate it with a file manager?how to fix my keyboard after a bash script messed it upShell script with select command to show a list of filesHow to stop the bash script when a condition fails?How to run C/C++ program using context menu (right click option)Question about select menus in bashCreate bash script that allows you to choose multiple options instead of just one?

Possible executive assistant job scam

Finding price of the power option

Forming error messages from a multidimensional associative array

Novel where a serial killer lives (almost) forever by swapping bodies

How can trusted host patterns be set dynamically?

Cooking octopus: simple boil or broth?

Will a nuclear country use nuclear weapons if attacked by conventional means by another nuclear country?

Can dual US-Canadian citizens travel to the US with an expired US passport but valid Canadian passport?

Could the Ancient Egyptian hieroglyphs have been deciphered without the Rosetta Stone with modern tech?

How many 1/day spells can a Warlock monster cast?

Do rainbows show spectral lines from the sun?

A professor commented that my research is too simple as compared to my colleagues. What does that mean about my future prospects?

Counter intuitive Bayesian theorem

How do I obtain the debian-installer for Ubuntu Server 18.04.3 LTS?

Is it possible to write a short story in 500 words?

Should plywood be missing on my roof?

MS in Mathematics, having trouble finding work outside teaching algebra

"Cобака на сене" - is this expression still in use or is it dated?

How do I test if regression slopes are statistically different?

How to avoid answering "what were you sick with"?

ssh login using public keys for users that do not (yet) exist

SD Card speed degrading and doesn't work on one of my cameras: can I do something?

In a shuttle launch, what would have happened if all three SSMEs failed during flight?

How to write the given block matrix



How to get ls in "select * in *?


How can I create a select menu in a shell script?Unity Icon for a bash ran programHow can I get Subliminal to work and then integrate it with a file manager?how to fix my keyboard after a bash script messed it upShell script with select command to show a list of filesHow to stop the bash script when a condition fails?How to run C/C++ program using context menu (right click option)Question about select menus in bashCreate bash script that allows you to choose multiple options instead of just one?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









0

















I want to program a script, which helps me installing thinks. ( I program it for bash exercises) I want to have a menu with "select option in options"



#!/bin/bash
download="~/Downloads/"
options='ls -l -d $download'
select option in $options; do
if [ "Test" = $option ]; then
clear
exit
else
echo hello
fi
done


The script should give every file in Download to select. And when its a tar.gz file it should install it in opt. But I do not know how to get the selection menu










share|improve this question





















  • 2





    Possible duplicate of How can I create a select menu in a shell script?

    – Melebius
    Jul 15 at 17:33











  • Try using backticks for the options variable, remove the '-d' and replace the '-l' with '-1' (the number one). Like this: options=ls -1 $download

    – Ryan J. Yoder
    Jul 15 at 17:49











  • It says now "ls: Can not access '~ / Downloads': file or directory not found"

    – Lockna
    Jul 15 at 18:01











  • Why are there space in your '~ / Downloads' ?

    – Rinzwind
    Jul 15 at 18:40











  • There aren't any spaces

    – Lockna
    Jul 15 at 18:45

















0

















I want to program a script, which helps me installing thinks. ( I program it for bash exercises) I want to have a menu with "select option in options"



#!/bin/bash
download="~/Downloads/"
options='ls -l -d $download'
select option in $options; do
if [ "Test" = $option ]; then
clear
exit
else
echo hello
fi
done


The script should give every file in Download to select. And when its a tar.gz file it should install it in opt. But I do not know how to get the selection menu










share|improve this question





















  • 2





    Possible duplicate of How can I create a select menu in a shell script?

    – Melebius
    Jul 15 at 17:33











  • Try using backticks for the options variable, remove the '-d' and replace the '-l' with '-1' (the number one). Like this: options=ls -1 $download

    – Ryan J. Yoder
    Jul 15 at 17:49











  • It says now "ls: Can not access '~ / Downloads': file or directory not found"

    – Lockna
    Jul 15 at 18:01











  • Why are there space in your '~ / Downloads' ?

    – Rinzwind
    Jul 15 at 18:40











  • There aren't any spaces

    – Lockna
    Jul 15 at 18:45













0












0








0








I want to program a script, which helps me installing thinks. ( I program it for bash exercises) I want to have a menu with "select option in options"



#!/bin/bash
download="~/Downloads/"
options='ls -l -d $download'
select option in $options; do
if [ "Test" = $option ]; then
clear
exit
else
echo hello
fi
done


The script should give every file in Download to select. And when its a tar.gz file it should install it in opt. But I do not know how to get the selection menu










share|improve this question















I want to program a script, which helps me installing thinks. ( I program it for bash exercises) I want to have a menu with "select option in options"



#!/bin/bash
download="~/Downloads/"
options='ls -l -d $download'
select option in $options; do
if [ "Test" = $option ]; then
clear
exit
else
echo hello
fi
done


The script should give every file in Download to select. And when its a tar.gz file it should install it in opt. But I do not know how to get the selection menu







command-line bash






share|improve this question














share|improve this question











share|improve this question




share|improve this question










asked Jul 15 at 17:31









LocknaLockna

31 bronze badge




31 bronze badge










  • 2





    Possible duplicate of How can I create a select menu in a shell script?

    – Melebius
    Jul 15 at 17:33











  • Try using backticks for the options variable, remove the '-d' and replace the '-l' with '-1' (the number one). Like this: options=ls -1 $download

    – Ryan J. Yoder
    Jul 15 at 17:49











  • It says now "ls: Can not access '~ / Downloads': file or directory not found"

    – Lockna
    Jul 15 at 18:01











  • Why are there space in your '~ / Downloads' ?

    – Rinzwind
    Jul 15 at 18:40











  • There aren't any spaces

    – Lockna
    Jul 15 at 18:45












  • 2





    Possible duplicate of How can I create a select menu in a shell script?

    – Melebius
    Jul 15 at 17:33











  • Try using backticks for the options variable, remove the '-d' and replace the '-l' with '-1' (the number one). Like this: options=ls -1 $download

    – Ryan J. Yoder
    Jul 15 at 17:49











  • It says now "ls: Can not access '~ / Downloads': file or directory not found"

    – Lockna
    Jul 15 at 18:01











  • Why are there space in your '~ / Downloads' ?

    – Rinzwind
    Jul 15 at 18:40











  • There aren't any spaces

    – Lockna
    Jul 15 at 18:45







2




2





Possible duplicate of How can I create a select menu in a shell script?

– Melebius
Jul 15 at 17:33





Possible duplicate of How can I create a select menu in a shell script?

– Melebius
Jul 15 at 17:33













Try using backticks for the options variable, remove the '-d' and replace the '-l' with '-1' (the number one). Like this: options=ls -1 $download

– Ryan J. Yoder
Jul 15 at 17:49





Try using backticks for the options variable, remove the '-d' and replace the '-l' with '-1' (the number one). Like this: options=ls -1 $download

– Ryan J. Yoder
Jul 15 at 17:49













It says now "ls: Can not access '~ / Downloads': file or directory not found"

– Lockna
Jul 15 at 18:01





It says now "ls: Can not access '~ / Downloads': file or directory not found"

– Lockna
Jul 15 at 18:01













Why are there space in your '~ / Downloads' ?

– Rinzwind
Jul 15 at 18:40





Why are there space in your '~ / Downloads' ?

– Rinzwind
Jul 15 at 18:40













There aren't any spaces

– Lockna
Jul 15 at 18:45





There aren't any spaces

– Lockna
Jul 15 at 18:45










3 Answers
3






active

oldest

votes


















1


















Here's a minimal working example. Note the following:



  1. tilde (~) doesn't expand inside double quotes, so needs to be outside. Consider replacing download=~/"Downloads" by download="$HOME/Downloads"


  2. don't use ls to generat a list of filename - it will break if any of the filenames has whitespace. Use a shell glob *, and put the results in an array


So:



#!/bin/bash

download=~/"Downloads"

options=( "$download"/* )

select option in "$options[@]" "quit"; do
case $option in
*.tar.gz)
echo "install some stuff"
;;
"quit")
break ;;
*)
echo "You chose $option" ;;
esac
done





share|improve this answer


























  • Writing my own answer and learning from yours :) I think you can shorten by one line with options=( ~/"Downloads"/* ) and deleting line before.

    – WinEunuuchs2Unix
    Jul 15 at 23:17












  • @WinEunuuchs2Unix sure you can - I was just trying to preserve as much as possible of the OP's code structure

    – steeldriver
    Jul 15 at 23:20











  • ahh good point, I'll be preserving none in my answer :)

    – WinEunuuchs2Unix
    Jul 15 at 23:21











  • Your answer worked. Thank you very much^^

    – Lockna
    Jul 22 at 10:35


















1


















You said you were learning bash so I thought you might appreciate a different kind of answer using zenity which is a popular GUI for bash built into Ubuntu.



Zenity Dialog Box



Here's what the zenity file selection dialog box looks like:



Downloads.sh screenshot.png



Calling the script



Here is how to call the script and what it outputs to your terminal when you select an item on the list:



$ Downloads.sh
Option: /home/rick/Downloads/nvhda.tar.xz


Instead of displaying "Option: " your version of the script will be running a tar command.



Downloads.sh bash script



#!/bin/bash

# NAME: Downloads.sh
# PATH: ~/askubuntu
# DESC: Select Download file
# DATE: July 15, 2019.
# NOTE: For: https://askubuntu.com/questions/1158485/how-to-get-ls-in-select-in

Array=( ~/"Downloads"/* )
while true; do
Option=$(zenity --list --title="Downloads.sh" --text="Select file"
--ok-label "TAR process" --cancel-label "Exit"
--width=800 --height=600 --column="Filename" "$Array[@]" 2>/dev/null)
[[ "$Option" == "" ]] && break
echo "Option: $Option"
done





share|improve this answer

































    0


















    The select command will try to display every field separated by spaces, tabs, and newline characters. So I don't think your sample will do what you want. You must not use "ls -l" for long listing or the permissions and ownerships and file sizes will all be fields displayed in the select statement results.



    Not sure if this is exactly what you were looking for, but it finds all files (no directories or symbolic links) and decides whether to process it as a PostgreSQL backup or just a regular file. You could always adapt it to look for whatever it is you hope to find in the downloads directory.



    You could look at changing the if statement to a case and try to find specific extensions. So you find the .tar or .gz or .cpio, and so on. Just figure out how to strip off the extension.



    #!/bin/bash
    download="/tempfs"
    cd $download
    options=$(ls -l |grep -v "^d" |awk 'print $9')
    select option in $options
    do
    if test "$(echo $option|grep ".dmp$")" = ""
    then
    echo "Process as normal file: $option"
    exit 0
    else
    echo "Process as pg_dump file: $option"
    exit 0
    fi
    done





    share|improve this answer



























      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "89"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );














      draft saved

      draft discarded
















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1158485%2fhow-to-get-ls-in-select-in%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown


























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1


















      Here's a minimal working example. Note the following:



      1. tilde (~) doesn't expand inside double quotes, so needs to be outside. Consider replacing download=~/"Downloads" by download="$HOME/Downloads"


      2. don't use ls to generat a list of filename - it will break if any of the filenames has whitespace. Use a shell glob *, and put the results in an array


      So:



      #!/bin/bash

      download=~/"Downloads"

      options=( "$download"/* )

      select option in "$options[@]" "quit"; do
      case $option in
      *.tar.gz)
      echo "install some stuff"
      ;;
      "quit")
      break ;;
      *)
      echo "You chose $option" ;;
      esac
      done





      share|improve this answer


























      • Writing my own answer and learning from yours :) I think you can shorten by one line with options=( ~/"Downloads"/* ) and deleting line before.

        – WinEunuuchs2Unix
        Jul 15 at 23:17












      • @WinEunuuchs2Unix sure you can - I was just trying to preserve as much as possible of the OP's code structure

        – steeldriver
        Jul 15 at 23:20











      • ahh good point, I'll be preserving none in my answer :)

        – WinEunuuchs2Unix
        Jul 15 at 23:21











      • Your answer worked. Thank you very much^^

        – Lockna
        Jul 22 at 10:35















      1


















      Here's a minimal working example. Note the following:



      1. tilde (~) doesn't expand inside double quotes, so needs to be outside. Consider replacing download=~/"Downloads" by download="$HOME/Downloads"


      2. don't use ls to generat a list of filename - it will break if any of the filenames has whitespace. Use a shell glob *, and put the results in an array


      So:



      #!/bin/bash

      download=~/"Downloads"

      options=( "$download"/* )

      select option in "$options[@]" "quit"; do
      case $option in
      *.tar.gz)
      echo "install some stuff"
      ;;
      "quit")
      break ;;
      *)
      echo "You chose $option" ;;
      esac
      done





      share|improve this answer


























      • Writing my own answer and learning from yours :) I think you can shorten by one line with options=( ~/"Downloads"/* ) and deleting line before.

        – WinEunuuchs2Unix
        Jul 15 at 23:17












      • @WinEunuuchs2Unix sure you can - I was just trying to preserve as much as possible of the OP's code structure

        – steeldriver
        Jul 15 at 23:20











      • ahh good point, I'll be preserving none in my answer :)

        – WinEunuuchs2Unix
        Jul 15 at 23:21











      • Your answer worked. Thank you very much^^

        – Lockna
        Jul 22 at 10:35













      1














      1










      1









      Here's a minimal working example. Note the following:



      1. tilde (~) doesn't expand inside double quotes, so needs to be outside. Consider replacing download=~/"Downloads" by download="$HOME/Downloads"


      2. don't use ls to generat a list of filename - it will break if any of the filenames has whitespace. Use a shell glob *, and put the results in an array


      So:



      #!/bin/bash

      download=~/"Downloads"

      options=( "$download"/* )

      select option in "$options[@]" "quit"; do
      case $option in
      *.tar.gz)
      echo "install some stuff"
      ;;
      "quit")
      break ;;
      *)
      echo "You chose $option" ;;
      esac
      done





      share|improve this answer














      Here's a minimal working example. Note the following:



      1. tilde (~) doesn't expand inside double quotes, so needs to be outside. Consider replacing download=~/"Downloads" by download="$HOME/Downloads"


      2. don't use ls to generat a list of filename - it will break if any of the filenames has whitespace. Use a shell glob *, and put the results in an array


      So:



      #!/bin/bash

      download=~/"Downloads"

      options=( "$download"/* )

      select option in "$options[@]" "quit"; do
      case $option in
      *.tar.gz)
      echo "install some stuff"
      ;;
      "quit")
      break ;;
      *)
      echo "You chose $option" ;;
      esac
      done






      share|improve this answer













      share|improve this answer




      share|improve this answer










      answered Jul 15 at 20:09









      steeldriversteeldriver

      81.3k12 gold badges132 silver badges218 bronze badges




      81.3k12 gold badges132 silver badges218 bronze badges















      • Writing my own answer and learning from yours :) I think you can shorten by one line with options=( ~/"Downloads"/* ) and deleting line before.

        – WinEunuuchs2Unix
        Jul 15 at 23:17












      • @WinEunuuchs2Unix sure you can - I was just trying to preserve as much as possible of the OP's code structure

        – steeldriver
        Jul 15 at 23:20











      • ahh good point, I'll be preserving none in my answer :)

        – WinEunuuchs2Unix
        Jul 15 at 23:21











      • Your answer worked. Thank you very much^^

        – Lockna
        Jul 22 at 10:35

















      • Writing my own answer and learning from yours :) I think you can shorten by one line with options=( ~/"Downloads"/* ) and deleting line before.

        – WinEunuuchs2Unix
        Jul 15 at 23:17












      • @WinEunuuchs2Unix sure you can - I was just trying to preserve as much as possible of the OP's code structure

        – steeldriver
        Jul 15 at 23:20











      • ahh good point, I'll be preserving none in my answer :)

        – WinEunuuchs2Unix
        Jul 15 at 23:21











      • Your answer worked. Thank you very much^^

        – Lockna
        Jul 22 at 10:35
















      Writing my own answer and learning from yours :) I think you can shorten by one line with options=( ~/"Downloads"/* ) and deleting line before.

      – WinEunuuchs2Unix
      Jul 15 at 23:17






      Writing my own answer and learning from yours :) I think you can shorten by one line with options=( ~/"Downloads"/* ) and deleting line before.

      – WinEunuuchs2Unix
      Jul 15 at 23:17














      @WinEunuuchs2Unix sure you can - I was just trying to preserve as much as possible of the OP's code structure

      – steeldriver
      Jul 15 at 23:20





      @WinEunuuchs2Unix sure you can - I was just trying to preserve as much as possible of the OP's code structure

      – steeldriver
      Jul 15 at 23:20













      ahh good point, I'll be preserving none in my answer :)

      – WinEunuuchs2Unix
      Jul 15 at 23:21





      ahh good point, I'll be preserving none in my answer :)

      – WinEunuuchs2Unix
      Jul 15 at 23:21













      Your answer worked. Thank you very much^^

      – Lockna
      Jul 22 at 10:35





      Your answer worked. Thank you very much^^

      – Lockna
      Jul 22 at 10:35













      1


















      You said you were learning bash so I thought you might appreciate a different kind of answer using zenity which is a popular GUI for bash built into Ubuntu.



      Zenity Dialog Box



      Here's what the zenity file selection dialog box looks like:



      Downloads.sh screenshot.png



      Calling the script



      Here is how to call the script and what it outputs to your terminal when you select an item on the list:



      $ Downloads.sh
      Option: /home/rick/Downloads/nvhda.tar.xz


      Instead of displaying "Option: " your version of the script will be running a tar command.



      Downloads.sh bash script



      #!/bin/bash

      # NAME: Downloads.sh
      # PATH: ~/askubuntu
      # DESC: Select Download file
      # DATE: July 15, 2019.
      # NOTE: For: https://askubuntu.com/questions/1158485/how-to-get-ls-in-select-in

      Array=( ~/"Downloads"/* )
      while true; do
      Option=$(zenity --list --title="Downloads.sh" --text="Select file"
      --ok-label "TAR process" --cancel-label "Exit"
      --width=800 --height=600 --column="Filename" "$Array[@]" 2>/dev/null)
      [[ "$Option" == "" ]] && break
      echo "Option: $Option"
      done





      share|improve this answer






























        1


















        You said you were learning bash so I thought you might appreciate a different kind of answer using zenity which is a popular GUI for bash built into Ubuntu.



        Zenity Dialog Box



        Here's what the zenity file selection dialog box looks like:



        Downloads.sh screenshot.png



        Calling the script



        Here is how to call the script and what it outputs to your terminal when you select an item on the list:



        $ Downloads.sh
        Option: /home/rick/Downloads/nvhda.tar.xz


        Instead of displaying "Option: " your version of the script will be running a tar command.



        Downloads.sh bash script



        #!/bin/bash

        # NAME: Downloads.sh
        # PATH: ~/askubuntu
        # DESC: Select Download file
        # DATE: July 15, 2019.
        # NOTE: For: https://askubuntu.com/questions/1158485/how-to-get-ls-in-select-in

        Array=( ~/"Downloads"/* )
        while true; do
        Option=$(zenity --list --title="Downloads.sh" --text="Select file"
        --ok-label "TAR process" --cancel-label "Exit"
        --width=800 --height=600 --column="Filename" "$Array[@]" 2>/dev/null)
        [[ "$Option" == "" ]] && break
        echo "Option: $Option"
        done





        share|improve this answer




























          1














          1










          1









          You said you were learning bash so I thought you might appreciate a different kind of answer using zenity which is a popular GUI for bash built into Ubuntu.



          Zenity Dialog Box



          Here's what the zenity file selection dialog box looks like:



          Downloads.sh screenshot.png



          Calling the script



          Here is how to call the script and what it outputs to your terminal when you select an item on the list:



          $ Downloads.sh
          Option: /home/rick/Downloads/nvhda.tar.xz


          Instead of displaying "Option: " your version of the script will be running a tar command.



          Downloads.sh bash script



          #!/bin/bash

          # NAME: Downloads.sh
          # PATH: ~/askubuntu
          # DESC: Select Download file
          # DATE: July 15, 2019.
          # NOTE: For: https://askubuntu.com/questions/1158485/how-to-get-ls-in-select-in

          Array=( ~/"Downloads"/* )
          while true; do
          Option=$(zenity --list --title="Downloads.sh" --text="Select file"
          --ok-label "TAR process" --cancel-label "Exit"
          --width=800 --height=600 --column="Filename" "$Array[@]" 2>/dev/null)
          [[ "$Option" == "" ]] && break
          echo "Option: $Option"
          done





          share|improve this answer














          You said you were learning bash so I thought you might appreciate a different kind of answer using zenity which is a popular GUI for bash built into Ubuntu.



          Zenity Dialog Box



          Here's what the zenity file selection dialog box looks like:



          Downloads.sh screenshot.png



          Calling the script



          Here is how to call the script and what it outputs to your terminal when you select an item on the list:



          $ Downloads.sh
          Option: /home/rick/Downloads/nvhda.tar.xz


          Instead of displaying "Option: " your version of the script will be running a tar command.



          Downloads.sh bash script



          #!/bin/bash

          # NAME: Downloads.sh
          # PATH: ~/askubuntu
          # DESC: Select Download file
          # DATE: July 15, 2019.
          # NOTE: For: https://askubuntu.com/questions/1158485/how-to-get-ls-in-select-in

          Array=( ~/"Downloads"/* )
          while true; do
          Option=$(zenity --list --title="Downloads.sh" --text="Select file"
          --ok-label "TAR process" --cancel-label "Exit"
          --width=800 --height=600 --column="Filename" "$Array[@]" 2>/dev/null)
          [[ "$Option" == "" ]] && break
          echo "Option: $Option"
          done






          share|improve this answer













          share|improve this answer




          share|improve this answer










          answered Jul 15 at 23:54









          WinEunuuchs2UnixWinEunuuchs2Unix

          60.4k18 gold badges122 silver badges236 bronze badges




          60.4k18 gold badges122 silver badges236 bronze badges
























              0


















              The select command will try to display every field separated by spaces, tabs, and newline characters. So I don't think your sample will do what you want. You must not use "ls -l" for long listing or the permissions and ownerships and file sizes will all be fields displayed in the select statement results.



              Not sure if this is exactly what you were looking for, but it finds all files (no directories or symbolic links) and decides whether to process it as a PostgreSQL backup or just a regular file. You could always adapt it to look for whatever it is you hope to find in the downloads directory.



              You could look at changing the if statement to a case and try to find specific extensions. So you find the .tar or .gz or .cpio, and so on. Just figure out how to strip off the extension.



              #!/bin/bash
              download="/tempfs"
              cd $download
              options=$(ls -l |grep -v "^d" |awk 'print $9')
              select option in $options
              do
              if test "$(echo $option|grep ".dmp$")" = ""
              then
              echo "Process as normal file: $option"
              exit 0
              else
              echo "Process as pg_dump file: $option"
              exit 0
              fi
              done





              share|improve this answer






























                0


















                The select command will try to display every field separated by spaces, tabs, and newline characters. So I don't think your sample will do what you want. You must not use "ls -l" for long listing or the permissions and ownerships and file sizes will all be fields displayed in the select statement results.



                Not sure if this is exactly what you were looking for, but it finds all files (no directories or symbolic links) and decides whether to process it as a PostgreSQL backup or just a regular file. You could always adapt it to look for whatever it is you hope to find in the downloads directory.



                You could look at changing the if statement to a case and try to find specific extensions. So you find the .tar or .gz or .cpio, and so on. Just figure out how to strip off the extension.



                #!/bin/bash
                download="/tempfs"
                cd $download
                options=$(ls -l |grep -v "^d" |awk 'print $9')
                select option in $options
                do
                if test "$(echo $option|grep ".dmp$")" = ""
                then
                echo "Process as normal file: $option"
                exit 0
                else
                echo "Process as pg_dump file: $option"
                exit 0
                fi
                done





                share|improve this answer




























                  0














                  0










                  0









                  The select command will try to display every field separated by spaces, tabs, and newline characters. So I don't think your sample will do what you want. You must not use "ls -l" for long listing or the permissions and ownerships and file sizes will all be fields displayed in the select statement results.



                  Not sure if this is exactly what you were looking for, but it finds all files (no directories or symbolic links) and decides whether to process it as a PostgreSQL backup or just a regular file. You could always adapt it to look for whatever it is you hope to find in the downloads directory.



                  You could look at changing the if statement to a case and try to find specific extensions. So you find the .tar or .gz or .cpio, and so on. Just figure out how to strip off the extension.



                  #!/bin/bash
                  download="/tempfs"
                  cd $download
                  options=$(ls -l |grep -v "^d" |awk 'print $9')
                  select option in $options
                  do
                  if test "$(echo $option|grep ".dmp$")" = ""
                  then
                  echo "Process as normal file: $option"
                  exit 0
                  else
                  echo "Process as pg_dump file: $option"
                  exit 0
                  fi
                  done





                  share|improve this answer














                  The select command will try to display every field separated by spaces, tabs, and newline characters. So I don't think your sample will do what you want. You must not use "ls -l" for long listing or the permissions and ownerships and file sizes will all be fields displayed in the select statement results.



                  Not sure if this is exactly what you were looking for, but it finds all files (no directories or symbolic links) and decides whether to process it as a PostgreSQL backup or just a regular file. You could always adapt it to look for whatever it is you hope to find in the downloads directory.



                  You could look at changing the if statement to a case and try to find specific extensions. So you find the .tar or .gz or .cpio, and so on. Just figure out how to strip off the extension.



                  #!/bin/bash
                  download="/tempfs"
                  cd $download
                  options=$(ls -l |grep -v "^d" |awk 'print $9')
                  select option in $options
                  do
                  if test "$(echo $option|grep ".dmp$")" = ""
                  then
                  echo "Process as normal file: $option"
                  exit 0
                  else
                  echo "Process as pg_dump file: $option"
                  exit 0
                  fi
                  done






                  share|improve this answer













                  share|improve this answer




                  share|improve this answer










                  answered Jul 15 at 19:50









                  S. NixonS. Nixon

                  595 bronze badges




                  595 bronze badges































                      draft saved

                      draft discarded















































                      Thanks for contributing an answer to Ask Ubuntu!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1158485%2fhow-to-get-ls-in-select-in%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown









                      Popular posts from this blog

                      Tamil (spriik) Luke uk diar | Nawigatjuun

                      Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

                      Training a classifier when some of the features are unknownWhy does Gradient Boosting regression predict negative values when there are no negative y-values in my training set?How to improve an existing (trained) classifier?What is effect when I set up some self defined predisctor variables?Why Matlab neural network classification returns decimal values on prediction dataset?Fitting and transforming text data in training, testing, and validation setsHow to quantify the performance of the classifier (multi-class SVM) using the test data?How do I control for some patients providing multiple samples in my training data?Training and Test setTraining a convolutional neural network for image denoising in MatlabShouldn't an autoencoder with #(neurons in hidden layer) = #(neurons in input layer) be “perfect”?