Added: 1 year ago
From: metalx1000
Views: 1,554
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:

All Comments (8)

Sign In or Sign Up now to post a comment!
  • Quoting error... examples in this video can fail if an argument contains whitespace.

    ~ $ a=('Kris' 'Tom' 'BOB Jenn'); for i in "${a[@]}"; do printf '%s\n' $i "$i"; done

    Kris

    Kris

    Tom

    Tom

    BOB

    Jenn

    BOB Jenn

  • Now, I'm a bit confused on how it works. I've never seen the "For" command used before, so it's because of that, but I do understand that the For command can make the variable "i", but the in command kind of baffles me. For *Variable* in *Array numbers*, other than that I get it, but I feel as though I should try looking for your other tutorial for the other commands.

  • @theif519: the "for" command will do something for each item inputted. so, for example:

    for i in *;do echo "$i is a file";done

    in this case the "*" will list all files in the current directory and create a loop for each one.

    you can also do this:

    for i in 1 2 3 4 5;do echo "$i";done

    which will output a loop for each number given the same as this:

    for i in {1..5};do echo "$i";done

    obviously if you wanted to count to 100 the shorter way would be {1..100}

    Hope I explained this well.

  • Thanks Sir you are best :)

  • thanks for the tutorials and keep them coming! but i had a hunch this would work and it does, to display all contents in an array echo ${names[*]}

  • @ybnormal798: Good call. Thanks.

  • thanks for your tutorial, really appreciate it. I'm having difficulty to understand, when or in what circumstance we have to put brackets and when we have to put( parenthesis. The other day i was working on a script, and it didn't work until, i've put 2 embedded parenthesis. And i don't know why, it was that way.

    So if you know about these an could explain , it would be great. Thanks.

  • @qcjn: Sure, I'll try to do a video on that soon. But, I'll try to give some examples now. Brackets [ and ] are used in things like if statements and while loop. Example:

    if [ $x = 1 ];then

    they are also used when creating arrays.

    humm, I just woke up so maybe it's because I'm tired, but I can't think of when I would use parenthesis ( and ). I'm sure they are used for something. I'll have to get back to you on that one.

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more