Results 1 to 7 of 7
  1. #1


    Member Since
    Jul 13, 2011
    Posts
    7
    Repeating things in the terminal.
    Is there a way to repeat something 30 times in terminal?

  2. #2

    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,782
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    Loops are your friend. This following example will print Hello x where x is a number:
    Code:
    for x in `seq 1 10`
    do
            echo Hello $x
    done
    The output of that is as follows:
    Code:
    Hello 1
    Hello 2
    Hello 3
    Hello 4
    Hello 5
    Hello 6
    Hello 7
    Hello 8
    Hello 9
    Hello 10
    Change the sequence parameters to 1 30 and that would happen 30 times. Once you change that, simply replace the echo line with the command you want to execute thirty times. So, for instance:
    Code:
    for x in `seq 1 30`
    do
            <your command>
    done
    Replace <your command> with the command you want executed and you're good to go.

    Save that as a shell script and simply execute it from the command line:
    Code:
    sh <path to script>
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

  3. #3

    Dysfunction's Avatar
    Member Since
    Mar 17, 2008
    Location
    Tucson, AZ
    Posts
    6,881
    Specs:
    Way... way too many specs to list.
    how bout...

    Code:
    #!/bin/bash
    x=1
    while [ $x -le 30 ]
    do
      echo "Welcome $x times"
      x=$(( $x + 1 ))
    done
    There's also estabishing as in for i in 1 2 3 4 5 6 7 etc.. and COUNT, COUNTER.. ohhh so many ways
    mike
    This machine kills fascists
    Got # ? phear the command line!

  4. #4

    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,782
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    As the Perl motto goes, "There's more than one way to do it."

    For the OP: you can take my script (and Dysfunction's) and make it into a command instead of a script. Mine would look like so:
    Code:
    for x in `seq 1 30` ; do echo $x ; done
    That's helpful if you don't want a script.
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

  5. #5


    Member Since
    Jul 13, 2011
    Posts
    7
    Would
    Code:
    echo 'How many times?'
    read numtimes
    for x in numtimes
    do
    touch file $filenum.txt
    done
    work?

  6. #6


    Member Since
    Jul 13, 2011
    Posts
    7
    ok, it does.(i tested it)
    However, the file incrementing did not. How would i do this? I want to make as many files as possible.

  7. #7


    Member Since
    Jul 13, 2011
    Posts
    7
    Ahhh, got it. That was confusing.
    Code:
    #! /bin/bash
    
    echo "Ready to crash your computer?"
    read yes
    echo "You entered yes. Why?"
    mkdir ~/Desktop/Files
    cd ~/Desktop/Files
    echo 'How many times?'
    read x
    y=99
    while [ $y -le $x ]
    do
      touch $y.txt
      y=$(( $y + 1 ))
    done
    Don't put a high number in.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Repeating Window that won't go away?
    By Dale2012 in forum OS X - Operating System
    Replies: 3
    Last Post: 12-07-2014, 07:34 AM
  2. repeating emails
    By Reedster in forum OS X - Apps and Games
    Replies: 0
    Last Post: 05-19-2012, 01:09 PM
  3. Help setting up a vpn and repeating
    By halimj7 in forum Internet, Networking, and Wireless
    Replies: 0
    Last Post: 07-22-2011, 03:35 PM
  4. URL name repeating itself using iweb
    By norb123show in forum Web Design and Hosting
    Replies: 1
    Last Post: 04-20-2011, 03:26 PM
  5. iCal repeating event
    By Resoman in forum OS X - Apps and Games
    Replies: 9
    Last Post: 12-02-2010, 08:24 PM

Posting Permissions

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