Find the answer to your Linux question:
Results 1 to 10 of 10
Hello, I've just started using bash and have a really simple problem, I've tried searching but I'm not sure what the problem is called I've wrote a simple script that ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2011
    Posts
    6

    Newbie Bash Multiple Entry problem


    Hello,

    I've just started using bash and have a really simple problem, I've tried searching but I'm not sure what the problem is called

    I've wrote a simple script that essentially takes input in from a line using read -e and then performs an action, the action is just to take information from one place.. say 10,000 files, then cut it into sections and copy elsewhere

    I've done this, but I want to enter multiple sections, I might want 3 or 4 sections from the source data

    Simply put I don't want to have to enter the command when the action has finished

    i.e currently

    enter data in line of what I want and where to put it
    action performed

    what I want is to..

    enter data in line
    enter different data in line
    enter different data in line

    action performed
    action performed
    action performed

    Thanks for your help

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    not sure I understand, do you mean this?
    Code:
    read -p "Enter action 1: " action1
    read -p "Enter action 2: " action2
    read -p "Enter action 3: " action3
    echo "action 1: $action1"
    echo "action 2: $action2"
    echo "action 3: $action3"

  3. #3
    Just Joined!
    Join Date
    Oct 2011
    Posts
    6
    Hi,

    Exactly that, but with perhaps 100 inputs. Its a messy script I intend to clean when its working.
    So as it stands the script takes a sequence of about 20,000 photos chooses a selection from them, renames and outputs

    However I have to enter the selections destination, start and end frame - then it processes the request, then I enter another selection

    I want to be able to enter a long list of shots I want, then for them all to be processed so I can just set it off and leave it

  4. #4
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Maybe you want command line arguments then? I'm not sure what you are requiring as input, but maybe something like:

    Code:
    #!/bin/bash
    declare -a args
    args=($@)
    num=${#args[*]}
    echo "You gave $num args"
    echo "arg 1 is ${args[0]}"
    echo "arg 2 is ${args[1]}"
    echo "arg 3 is ${args[2]}"
    Then you'd pass all your inputs on the command line, when you run the script.e.g.:

    Code:
    ./myscript.sh arg1 arg2 blah "variable with spaces" 20 foo bar arg8

  5. #5
    Just Joined!
    Join Date
    Oct 2011
    Posts
    6
    Thanks, I'll give that go

  6. #6
    Just Joined!
    Join Date
    Oct 2011
    Posts
    6
    Thanks to the help above I got the scripts working, so now I'm just fine tuning. I've been looking around at sed/awk etc but I can't work out the following problem. All i want is for a user to enter timecode into a user line in the format of 01:04:05:05 etc and the line to be broken up. So far I'm working the min, sec and frame separately so they are entered as 4 5 5 and given anchors using read -e

    i.e.
    read -e startmin startsec startframe
    start=$[startmin * 24 * 60 + startsec * 24 + startframe - handles]

    How do I translate that so that the input data is separated by a colon, is it as simple as telling read how to process it or do I need to format the information after it's been put in? Essentially

    read -e ignore:startmin:startsec:startframe

    Sorry for the questions, I'm finding half the trouble being that I don't know how to go about the for mating the instructions so googleing rarely helps

  7. #7
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    something like this?

    Code:
    read -p "Enter timecode (e.g. 01:04:05:05): " input
    declare -a args
    if [ -n "$input" ]; then
      args=($(echo $input|sed -e 's|:| |g'))
      echo "args given: ${args[*]}"
      if [ ${#args[*]} -ne 4 ]; then
        echo "Wrong number of args"
        exit 1
      else
        firstarg=${args[0]}
        secondarg=${args[1]}
        thirdarg=${args[2]}
        fourtharg=${args[3]}
      fi
    else
      echo No args given
      exit 1
    fi
    
    echo first arg: $firstarg
    You could wrap it in a loop so that it kept asking you until you give it the right format as input.

  8. #8
    Just Joined!
    Join Date
    Oct 2011
    Posts
    6
    Exactly like that, Thankyou so much

  9. #9
    Just Joined!
    Join Date
    Oct 2011
    Posts
    6
    Hello,

    Thanks for all your help so far with. I've another 2 simple Friday morning questions though if someone could explain to me, or at least nudge me in the right direction as to what i should be looking at

    I've a command that looks for the earliest numbered dpx frame and reads the timecode embedded in the dpxheader. I use a separate programme to find all the results then grep to find the line I'm interested in, which I want to store as input. so far I have...

    read -p "Enter path :" path
    dpxreader $path.*.dpx -ge 0 | grep "timecode*"

    So the path is entered, the programme finds the earliest file when it is not starting at 0 or 1, reads the header and prints the timecode information. What I want to do is

    First, The path to be more flexible, so it will always end with the .dpx files and will overlook any other sub directories that are put in (i.e. roll it came from/geometry folder/another random folder/fsdfdsf.dpx essentially all you need is a name and it will overlook all subs within that folder until it reaches the final dpx file

    Second, This must be simple, but how do I store the grep readout as input? Currently I have to print it then enter it separately, I'm sure there must be a way to store the grep found line's timecode information I jyst can't seem to google what it is

    Thanks again for all your patience and help with this

  10. #10
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    I don't understand what you mean by the path needing to be more flexible. When you prompt the user for input, what do you want them to respond with? a file, or a directory, or a bunch of files, or what?

    It looks as though the dpxreader takes as command line arguments any files ending in dpx in the path specified.

    I don't quite get this code:

    Code:
    dpxreader $path.*.dpx -ge 0 | grep "timecode*"
    is the -ge 0 bit actually arguments being passed to the program dpxreader or you utilizing the bash built-in numerical comparisons? If the latter, I think you need to rework it a bit. What does the output of dpxreader look like?

    Is dpxreader a shell script, and if so, can you post relevant portions of it?

    Save the output of grep like:

    Code:
    output=$(dpxreader $path.*.dpx -ge 0 | grep "timecode*")

Posting Permissions

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