Bash script read input and feh

I was trying to make a quick script to organize some pictures using feh to display the picture in question and then using bash to read a character from the keyboard and move to a folder based on that letter. Problem is it opens every image in the folder at the start (which is overwhelming). I want to go image by image.
heres the simplified script. There would be different if statements for each letter/dir pair
#!/bin/bash
ls | while read file1; do #while loop over all images in the dir
feh $file1 &
read ch1
if [[ $ch1 == "e" ]]
then
mv $file1 /PATH/hawaii
echo "moving to hawaii"
pkill feh
fi
Problem seems to be that the script doesn't wait to receive the input $ch1 before moving on to the next iteration of the loop.  Except that when I do something simpler like the following it does seem to wait on the input
while
   echo '1'
   read ch1
   echo '2'
   echo '3'

for f in *; do $(feh $f)& read g; if [[ "$g" == "e" ]]; then mv -v $f ../tested; fi;pkill feh; done;
waits for me to enter something before checking whether to move the image and closing the image and moving to the next.

Similar Messages

  • Bash script user input and revision technique requested

    In a bash script, I have a need to present the contents of a variable to the user, so that he can "revise" the value if needed, or just hit enter if no revision is required. The objective is to reduce keyboard effort to just revising a presented value.
    The "hit enter to continue" part is easy.
    The "revise" part is the problem for me.
    To illustrate using an example:
    #! /bin/bash
    position_var=30.39
    echo -n "Revise Position if required:${position_var}"
    #then some kind of read position_var ??
    How can I make the position_var available to the user to edit and resubmit?
    Thanks
    steve.
    Last edited by stevepa (2012-02-28 17:31:56)

    The above solution is good okay for a general shell script, bash has a feature for what you want though. (see below)
    If however the content of the variable is bigger (multiple lines, or a really LONG line you don't want to have to retype), you have 2 options:
    Write it to a temp file and fire up $EDITOR (if that's not set, you can default to nano or vi, whichever you can find with $(which ...)).
    The other idea that comes to mind is using 'expect' to present a prefilled prompt the user can edit... I'll have to test this...
    EDIT: Can't think of an easy way to do that with expect... mhh...
    EDIT2: Specifically for bash:
    read -p "Revise Position if required: " -i "$current" -e new
    with the -e flag, $current will be what the line is prefilled with, and $new will contain the result.
    Last edited by Blµb (2012-02-28 18:14:55)

  • My first bash script - update mirrors and then update your system.

    Like the title says, this is my first attempt at a bash script.
    I wrote it to make it a tiny bit easier for my wife to keep her system up to date without needing to remember the terminal commands.  She runs it via an entry in her openbox menu.
    It calls on reflector to check all available mirrors for the most up to date and then use rankmirrors to find the fastest 5 and write them to /etc/pacmand.d/mirrorlist
    Finally, it syncs and upgrades via the command pacman -Syyu
    #!/bin/bash
    # runs reflector to optimize mirrors
    echo "I'm afraid I can't do that Dave"
    sudo reflector -l 5 -r -o /etc/pacman.d/mirrorlist
    echo " I hope you trust me..."
    echo " "
    sleep 2s
    # updates system
    sudo pacman -Syyu

    I've scavenged some code to take care of the root thing, but why rebase vs pacman?  After reading up on rebase a bit, I'm not quite sure how to use it to complete the upgrade once it's updated everything.

  • Differences in writting bash-script in Solaris and in RHEL?

    I wrote a script 'checkinstall' as follow and it works fine by RHEL:
    [code]
    #!/bin/sh
    HOSTNAME=hostname
    echo $HOSTNAME
    if [ $HOSTNAME == "S001AP99-TEST" ]; then
        echo This is the wrong machine.\
        echo "\nAbouting installation.\n\n"
        exit 1
    fi
    exit 0
    [/code]
    But when I run this by Solaris I got:
    # ./checkinstall
    hostname
    ./checkinstall: test: unknown operator ==
    I changed the line HOSTNAME=hostname to HOSTNAME=`hostname` and it outputs the correct hostname.
    But I still get error:
    # ./checkinstall
    S001AP99-TEST
    ./checkinstall: test: unknown operator ==

    If you want to create bash scripts, then the first step is to set the right shell in the first line => #!/bin/bash
    Then, after this important step, you can try if this works. Oh surprise, it's working.

  • Bash script "open terminal and launch command

    I need a script to do this:
    launch a terminal, from this change working directory and then launch a command; the terminal have to remain opened after the command execution.
    Something like:
    $terminal cd $dir && $command
    If I open a terminal and I do:
    cd $dir && $command
    it works
    If I do a .sh script with this:
    xterm -hold -e cd $dir && $command
    or
    terminal -H -x cd $dir && $command
    when I launch it (the script) it doesn't work.
    Last edited by buntolo (2012-01-05 23:44:52)

    karol wrote:
    xterm -hold -e "cd ~/test/ && ls"
    works too.
    I don't know what $command do you mean, but this will list th ~/test directory.
    It works also for me.
    With urxvt and xfce4-terminal don't work.
    But xterm is too minimalist, is there an advanced terminal based on it?
    And I don't unerstand why it doesn't work for xfce4-terminal but for it does for xterm...
    man xfce4-terminal:
    -H, --hold
    Causes the terminal to be kept around after the child command has terminated
    -e, --command=command
    Execute command inside the terminal
    man xterm:
    -hold
    Turn on the hold resource, i.e., xterm will not immediately destroy its window when the shell command completes. It will wait until you use the window manager to destroy/kill the window, or if you use the menu entries that send a signal, e.g., HUP or KILL.
    -e program [ arguments ... ]
    This option specifies the program (and its command line arguments) to be run in the xterm window. It also sets the window title and icon name to be the basename of the program being executed if neither -T nor -n are given on the command line. This must be the last option on the command line.
    What the ...?
    Is only my opinion that there aren't differences between:
    terminal -H -e "cd $dir && $command"
    and
    xterm -hold -e "cd $dir && $command"
    Last edited by buntolo (2012-01-06 13:11:58)

  • Barcode reader input and JTextField

    Hi Everybody,
    here is my problem: I have to read the input from a Barcode reader into a JTextField;
    I have a Listener attached to the JTextField Document which works fine. The problem is that the listener is invoked as many time as the characters input (e.g 12 times, if the scanned barcode has 12 digits)
    How do I know the input is complete if I don't know the length of the expected input?
    Thanks in advance fon any help or ideas

    What kind of Listener have you attached to the TextField?
    Most bar code readers can be configured to finish the scan with a carriage return in which case if you use an ActionListener then it would solve your problem

  • Can't get conky-cli and bash scripts to both display in dwm statusbar!

    I'm trying to configure my dwm status bar to display some simple information using conky-cli and bash scripts. At first I tried just letting conky run the bash scripts (for network and volume state), but this increased my cpu usage by about 5%, which is significant considering I normally have 1-3% usage when idle. Also, I wanted to keep conky because it makes the display of certain information easy, such as cpu & RAM usage.
    The problem is I'm having trouble getting both to display side by side. Here are the relevant parts of my .xinitrc:
    network(){
    iwconfig wlan0 2>&1 | grep -q no\ wireless\ extensions\. && {
    echo wired
    exit 0
    essid=`iwconfig wlan0 | awk -F '"' '/ESSID/ {print $2}'`
    stngth=`iwconfig wlan0 | awk -F '=' '/Quality/ {print $2}' | cut -d '/' -f 1`
    bars=`expr $stngth / 10`
    case $bars in
    0) bar='[-------]' ;;
    1) bar='[#------]' ;;
    2) bar='[##-----]' ;;
    3) bar='[###----]' ;;
    4) bar='[####---]' ;;
    5) bar='[#####--]' ;;
    6) bar='[######-]' ;;
    7) bar='[#######]' ;;
    *) bar='[--!!!--]' ;;
    esac
    echo $essid$bar
    exit 0
    volume(){
    vol=$(amixer get Master | awk -F'[]%[]' '/%/ {if ($7 == "off") { print "MM" } else { print $2 }}' | head -n 1)
    echo Vol: $vol%
    exit 0
    conky | while true; read line; do xsetroot -name "`$line` `volume` `network` `date '+%a %m-%d-%Y %I:%M%p'`"; done &
    exec dwm
    (let me know if it would help to post any other files)
    For some reason when I run this I only get the network/volume scripts and date running, updating every second (I think). The conky line just doesn't show up. I don't know what could be wrong, since I didn't see any error messages.
    An even better solution would be to just have shell scripts to display CPU and MEM usage. I have a dual-core cpu, cpu0 and cpu1. I'd like to see both percentages if possible, or at least a percentage that is an accurate average of the two or something. In conky-cli I have something that shows:
    cpu0/1: xx% xx%
    Also, seeing RAM usage would help a lot. In conky it shows:
    mem: xx% (xxxMB)
    These are the ways I would like to have bash scripts show them, if possible, but I have zero skill in bash programming. I made this an option in case it's easier/cleaner/less resource hungry than a conky solution. Personally, if they're about the same in these aspects, I would prefer something with conky and the shell scripts because conky is so extensible, yet it's only flaw is executing scripts with minimal resource usage.
    Help?

    Thanks. I was thinking of using load average to save a few characters, but I didn't quite understand the numbers. I'll try that once I get to my Linux box, but could you please explain or post a link to something that explains load average (what's low, high, normal, etc.)?
    EDIT: I found a website that explains loadavg. I now have my dwm status bar displaying it perfectly (yay!). Now I just need to add a few more things like battery status, etc. and I might be done. I'll probably post here if I have more questions, though.
    Thanks for your help!
    Last edited by Allamgir (2009-07-18 14:41:11)

  • How to detect line break while reading input ?

    Hi all,
    I am reading the user input from standard input.
    I want to detect the line break. So that I can stop reading input and proceed processing the string.
    Actually I am getting the SQL query as input and after that I am executing the same by passing it to a function.
    Pl. do reply me.
       Scanner scanner = new Scanner(System.in);             
            while(scanner.hasNext())
                 temp=scanner.next();
                  sql=sql.concat(" "+temp);
                 if(scanner.next=="\n")
                            break;
           System.out.println(sql);
           sqlTool.executeSQL(sql);
    The above is not working properly.

    But if new line comes, what will be it's value?Empty lines are discarded by the scanner.
    Kaj

  • [SOLVED] problem with spaces and ls command in bash script

    I am going mad with a bash script I am trying to finish. The ls command is driving me mad with spaces in path names. This is the portion of my script that is giving me trouble:
    HOMEDIR="/home/panos/Web Site"
    for file in $(find "$HOMEDIR" -type f)
    do
    if [ "$(dateDiff -d $(ls -lh "$file" | awk '{ print $6 }') "$(date +%F)")" -gt 30 ];
    then echo -e "File $file is $(dateDiff -d $(ls -lh "$file" | awk '{ print $6 }') "$(date +%F)") old\r" >> /home/panos/scripts/temp;
    fi
    done
    The dateDiff() function is defined earlier and the script works fine when I change the HOMEDIR variable to a path where there are no spaces in directory and file names. I have isolated the problem to the ls command, so a simpler code sample that also doesn't work correctly with path names with spaces is this:
    #!/bin/bash
    HOMEDIR="/home/panos/test dir"
    for file in $(find "$HOMEDIR" -type f)
    do
    ls -lh "$file"
    done
    TIA
    Last edited by panosk (2009-11-08 21:55:31)

    oops, brain fart. *flushes with embarrassment*
    -- Edit --
    BTW, for this kind of thing, I usually do something like:
    find "$HOMEDIR" -type f | while read file ; do something with "$file" ; done
    Or put those in an array:
    IFS=$'\n' ; files=($(find "$HOMEDIR" -type f)) ; unset IFS
    for file in "${files[@]}" ; do something with "$file" ; done
    The later method is useful when elements of "${files[@]}" will be used multiple times across the script.
    Last edited by lolilolicon (2009-11-09 08:13:07)

  • Bash script: Rotate your wallpaper and SLiM theme at the same time

    EDIT;
    I've decided I should really thank Cerebral for his help with writing this script; this thank you should have been here from the get go.
    After writing:
    #!/usr/bin
    echo "Hello World!"
    I wrote a script to rotate my fluxbox background and SLiM theme at the same time, so I could have a contiuously changing background and still have a smooth transition from SLiM to fluxbox.  (It just looks so much cooler when both have matching backgrounds).  By the time you finish reading it, and configuring your box so it will work, you will probably have decided you could have writtin your own, better script to do the same thing.  But, on the off chance anybody finds use for it, here it is:
    (this should be obvious, but: don't run this script without at least reading the comments)
    #!/bin/bash
    #this is a script to rotate a number of backgrounds
    #to be shared by the fluxbox desktop and SLiM login manager.
    #it is the first meaningful script I've written. It may be
    #freely distributed and used with the understanding that you are
    #using it at your own risk.
    #Before running this script you need to check that your SLiM
    #themes are installed to the path /usr/share/slim/themes, which
    #is the defulat path for installation in Arch. Here are some
    #other things you need to set up:
    #1. create (if you don't have it) the directory /usr/share/wallpapers
    #2. create a wallpaper in /usr/share/wallpapers called 'dummy' by copying
    #you current wallpaper to that filename
    #3. set your window manager to display the wallpaper 'dummy', this works fine
    #using a style overlay in fluxbox, I haven't tested it with any other window
    #manager, but I don't see why this would cause a problem.
    #4. create a directory /usr/share/slim/themes/current, you can copy one of
    #your slim themes into that directory if you want. (this will prevent you
    #from seeing some error messages the first time you run the script)
    #5. define the names of the themes you want to rotate, in order for this
    #script to work, you must name them "themeNUMBER", where NUMBER is replaced
    #by an integer. Your themes must be numbered consecutively, start with 1
    # that is:
    #theme1 , theme2, theme3, etc. , theme305
    #If you don't number consecutively, this script will not run properly. You
    #must also define the total number of themes as "rotate_number"
    #6. Check if the script runs, if it does, you should change /etc/slim.conf to
    #use the theme "current"
    #7. This theme will now rotate your SLiM theme and wallpaper in such a way as
    #to make them match each other. Note that SLiM will not let you change themes
    #"on the fly", (as of July 6, 2008), so changes will not be apparent unless you
    #restart SLiM. I run the script before I run slim in my etc/rc.local local
    #script, so each time I reboot I get different wallpaper / login background.
    #Fred Drueck 2008
    #Define here all themes to be rotated and the total number of
    #themes to rotate:
    rotate_number=9
    theme1=/usr/share/slim/themes/default
    theme2=/usr/share/slim/themes/lake
    theme3=/usr/share/slim/themes/lunar
    theme4=/usr/share/slim/themes/flower2
    theme5=/usr/share/slim/themes/the-light
    theme6=/usr/share/slim/themes/mindlock
    theme7=/usr/share/slim/themes/parallel-dimensions
    theme8=/usr/share/slim/themes/wave
    theme9=/usr/share/slim/themes/fingerprint
    #check you are running this script as super-user:
    if [ $(id -u) != "0" ]; then
    echo "You must be the superuser to run this script" >&2
    exit 1
    fi
    echo "rotating themes"
    #figure out which theme is currently set, then name it as the variable
    #"last theme number", otherwise set last theme number as 0
    if [ -f /usr/share/slim/themes/current/current_theme_number ]
    then
    echo "checking current theme"
    cd /usr/share/slim/themes/current/
    eval last_theme_number=$(cat /usr/share/slim/themes/current/current_theme_number)
    echo $last_theme_number
    else
    echo "no theme is currently set, using theme 1"
    last_theme_number=0
    echo $1 > /usr/share/slim/themes/current/current_theme_number
    fi
    #set the new theme number
    eval new_theme_number=$(($(($last_theme_number % $rotate_number))+1))
    #select the new theme
    placeholder=theme
    eval new_theme=\$$placeholder$new_theme_number
    echo $new_theme
    #now clean out the "current" theme where I keep the current
    #theme for slim
    rm /usr/share/slim/themes/current/background*
    rm /usr/share/slim/themes/current/panel*
    rm /usr/share/slim/themes/current/slim.theme
    #the wildcards are there since the themes use jpg and png files
    cp $new_theme/background* /usr/share/slim/themes/current
    cp $new_theme/panel* /usr/share/slim/themes/current
    cp $new_theme/slim.theme /usr/share/slim/themes/current
    #increase the theme number, but first clear the old file
    rm /usr/share/slim/themes/current/current_theme_number
    echo $new_theme_number > /usr/share/slim/themes/current/current_theme_number
    #copy over the dummy wallpaper in "/usr/share/wallpapers" (with the theme
    #background file
    cp $new_theme/background* /usr/share/wallpapers/dummy
    exit 0
    Last edited by pseudonomous (2008-07-07 21:59:42)

    oh i forgot to mention... its rotating while moving. i.e. is doesn't have to stop rotate and then continue back to origin.

  • Iwl3945 and dhcpcd workaround - bash script

    I got tired of typing every command by hand all the time, so i made this simple bash script to do this for me...
    edit the script with your preferences and settings and run it as root. The script sets a static ip, and all the shizzle thats needed to have a workaround for the dhcp not working
    And im a newbie in bash programming, so please dont flame
    anywho, please give med feedback if theres something i could do different and better
    wlan script

    Correct me if I'm wrong, but you could simply add the rmmod / modprobe stuff and all that in PRE_UP='' in any of your netcfg profiles and the just run netcfg <profile>.

  • Double-clicking a Bash script and having it execute in it's directory

    Hi. I'm having some trouble with a Bash script I've been working on.
    The first command in the script is to copy all of the contents of the directory it's located in (including itself) to another folder.
    The Bash command I'm using is:
    cp -R . "/Some/Other/Folder/"
    This works fine when I run the program from the Terminal. E.g.: ./testscript
    But, I need this script to be double clickable in the Finder. I've associated it with Terminal, but when I double-click on it, instead of copying the files from the script's local folder, it starts recursively copying files from the home folder!
    I think this is because when I double-click on the script, it starts a new Terminal window at the home folder, and the dot portion of "cp ." now refers to the home folder, instead of the directory containing the script.
    Can anyone help me figure out how to be able to double click on the script to run it, yet have the script start in it's original folder?
    Thanks for any help.
    -Bassam
    Macbook Pro   Mac OS X (10.4.6)   Recently switched from Windows XP

    Thanks Steve, that worked perfectly.
    I did have to add a / to "$myFolder/" in the second line, so that the contents of the folder was copied, not the folder itself.
    Thanks!

  • Simultaneously read more than one input and generate output

    Is it possible To simultaneously read more than one input and generate outputs depending on these inputs? If this isn't possible what is the best way to go about making some sort of timed loop that will read an input, read the next input, decide whether or not to output and so on. Hope someone can help. Thanks.Message Edited by Esmith13 on 05-25-2005 01:36 PM

    Hi,
    You should look at the synchronized examples for analog input and output that can be found in the example finder under:
    Help>>Find Examples>>Hardware Input and Output>>DAQmx>>Synchronization>>Multi-Function
    These will get you started to being able to handle multiple tasks at the same time.
    I hope this helps. Have a Great Day!
    George

  • Get user input and find file and read it.....argh

    Ok, so I have to write a program that asks a user for the name of the file they want opened and then it is to read it and then display the max score and the minimum score on the file. also to display the average score on the file. Along with that it is supposed to display how many As, Bs, Cs, Ds, and Fs were on the file IE: a: 1 b: 3 c: 0 d: 4 f: 1. etc.
    Also, the next part is to have the program open the input file and then write all the information to an output file. I was able to do this and have the output file show the peoples names and their score along wtih their grade adn then the whole score average at the end of the output file....
    My question is how do I do the first part by asking the user for the name of file and then for the program to find the file and then display the max, min, average and how many letter grades the class got?

    this is what i have so far and the code before didnt work with JCreator, came up with lots of errors......
    What do i have to do to get the max value and min value to display along with the amount of As, Bs, Cs, Ds, and Fs????
    import java.io.*;
    class extest
    public static void main(String [] args) throws IOException
    // First, open the input file
    TextReader filein = new TextReader(new FileInputStream("test.txt"));
    // Read our number
    int x;
    x = filein.readInt();
    String [] first=new String[x];
    String [] last=new String[x];
    int [] score=new int[x];
    // load data from the input file test1.txt
    for (int i=0; i<x; i++)
    first=filein.readWord();
    last[i]=filein.readWord();
    score[i]=filein.readInt();
         WriteTestFile(first, last, score, x);
    public static void WriteTestFile(String f[], String last[], int score[], int x)
    double average=0;
    // Next, open the output file
    try
    PrintWriter fileout = new PrintWriter(
    new FileWriter("grade.txt") );
    // OK, now write to the file
    fileout.println(x);
    for (int i=0; i<x; i++)
    average=average+score[i];
    if (score[i]>90)
    fileout.println(f[i]+" "+last[i]+" " + score[i] +": "+"A");
    else if (score[i]>80)
    fileout.println(f[i]+" "+last[i]+ " " + score[i] + ": "+"B");
    else if (score[i]>70)
    fileout.println(f[i]+" "+last[i]+ " " +score[i] + ": "+"C");
    else if (score[i]>60)
    fileout.println(f[i]+" "+last[i]+ " " +score[i] + ": "+"D");
    else
    fileout.println(f[i]+" "+last[i]+" " +score[i] + ": "+"F");
    fileout.println("The average score of the class is "+average/x);
    // we're done with the output file
    fileout.close();
    catch (IOException e)
    throw new RuntimeException(e.toString());
    System.out.println("***** Welcome to the Grade Program! *****");
         System.out.println("");
         System.out.println("Please enter the name of the file you want to open: ");
         TextReader input = new TextReader(System.in);
         String fileName = input.readLine();
    System.out.println("The average of the scores is: "+average/x);
    System.out.println("The maximum score is: ");
    System.out.println("The minimum score is: ");
    System.out.println("Number of scores by letter grade:");
    System.out.println("A: ");
    System.out.println("B: ");
    System.out.println("C: ");
    System.out.println("D: ");
    System.out.println("F: ");

  • Read, Modify and Apply Report XML using Java Script

    Hi Guys,
    Is there any way that we can Pragmatically Read, Modify and Apply Report XML using Java Script or some other way.
    Thanks
    Kaushik
    Edited by: Kaushik K on Jun 20, 2012 8:36 PM

    Requirement ::
    Users should be able to add Column to the Report Dynamically at Runtime.
    (There are around 1000+ Users, Answers Approach is not acceptable)
    So we are planning to provide a Multi Select / Shuttle Box Option for Users to add Columns dynamically. (Only for Table View)
    What we planned to DO ::
    Create a Presentation Variable Prompt, Which reads the Metadata Table (Presentation Table.Column Name, populated using the Metadata Dictionary)
    And Create a report with One Column and the Column Fx like @{var_dynamic_columns}{'"Time"."Year","Time"."Month"'}
    With this, OBIEE is rewriting the Logical SQL Currently as "Select "Time"."Year","Time"."Month" from "A - Sample Sales" "
    But getting an error
    The number of columns returned in retrieving column metadata was invalid (expected: 1; received: 2)
    So we want to see, if we can rewrite the Advanced XML of the Report to have dynamic columns based on the Values from the Presentation Variable.
    Please help me if this is a viable solution or any other better solution.

Maybe you are looking for

  • How to find out which meta process chain a local chain is involved in

    Hello experts, i would like to know how a local process chain is started by a meta chain. I have a local chain running every day. It is involved in a meta chain. How can i find out the meta chain in which the local chain is involved. I appreciate eve

  • Apple Application Support was not found help!!!!!

    A few days ago i got on iTunes but this error message came up saying Apple Application Support was not found. Apple Application Support is required to run iTunes. Please uninstall iTunes, then install iTunes again. Error 2 (Windows error 2) I have lo

  • Calling a Host Command

    Dear Friends, Is it posible to call a host command (windows) from PLSQL (Oracle 9i) ? Thanks. Jai

  • Mail jam

    I apparently irritated my mail program by trying to send a message with an overly large attachment. The offending file is in the Draft list. If I so much as try to select it (in order to get it to Trash), I get the dred "spinning beach ball of death.

  • SAP Certified Logo / S-userid ???

    Hello friends, Last week i have cleared C_TADM51_70 : SAP Certified Technology Associate - System Administration (Oracle DB) with SAP NetWeaver 7.0 test. I have seen few threads regarding discussion on : SAP Certified Logo/Technical Consultant Logo S