LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-19-2019, 01:21 PM   #16
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 15,649

Rep: Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129

Quote:
Originally Posted by chrism01 View Post
I'm surprised no-one suggested 'seq'
Code:
for num in $( seq 1 3 )
do
	mkdir BOINC_${num}
done
probably because it is the slowest one.
To the original post, the syntax was incorrect, see man page of bash
Code:
A sequence expression takes the form {x..y[..incr]}, where x and y are either integers or single characters,  and incr,  an  optional  increment, is an integer.
When integers are supplied, the expression expands to each number between x and y, inclusive.
Code:
for x in {100..102}
do 
   echo mkdir "BOINC_$x";
done
works as expected.
 
Old 12-21-2019, 09:35 PM   #17
Skillz
Member
 
Registered: Sep 2007
Posts: 252

Rep: Reputation: 32
Can confirm this works

Code:
#!/usr/bin/bash
n=100;
max=102;
while [ "$n" -le "$max" ]; do
  /usr/bin/boinc --daemon --allow_multiple_clients --dir "/usr/bin/multiboinc/BOINC_$n" --gui_rpc_port 50$n &
  n=`expr "$n" + 1`;
done
 
Old 12-22-2019, 11:00 AM   #18
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Older: Coherent, MacOS, Red Hat, Big Iron IXs: AIX, Solaris, Tru64
Posts: 2,185

Rep: Reputation: 367Reputation: 367Reputation: 367Reputation: 367
Quote:
Originally Posted by gilesaj001 View Post
I want to create multiple folders using the for loop and I have been trying to figure it out now for a while and can't seem to get the right syntax. I want to create multiple folders in the folder i run the script in called BOINC_100 BOINC_101 BOINC_102 etc I have tried a lot of things and the only one I have gotten to run is as follows:

Code:
#!/bin/bash
for x in {100..1..101}  
do
mkdir "BOINC_$x"
done
But instead of creating multiple folders it just creates one folder called BOINC_{100..101..1}
Are you sure this is what your for-loop was?

Before writing the whole script that creates, potentially, a mess you'll have to clean up, try testing the sequence generation using 'echo':
Code:
$ echo {0..100..5}                    # Just an example
0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100
$ echo {100..1..101}                  # Your sequence
100
The only way I can see that you could have had that sequence generator show up in the directory name would have been to enclose it in quotes: for x in "{100..1..101}".
 
  


Reply

Tags
for loop, loop


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 9 07-28-2015 04:49 PM
bash loop within a loop for mysql ops br8kwall Programming 10 04-30-2008 04:50 AM
converting shell while loop to for loop farkus888 Programming 8 09-12-2007 03:30 AM
for loop only works properly on first loop symo0009 Programming 1 12-25-2005 06:17 PM
while loop or for loop? mijohnst Programming 18 11-21-2005 05:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration