Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3963374
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:12:27+00:00 2026-05-20T03:12:27+00:00

I’m writing a simple script to generate all combinations of a and b of

  • 0

I’m writing a simple script to generate all combinations of a and b of a given length (say 10). I want to be able to do this on a command line (I know this is fairly easy if I just put everything in a bash script file and execute it). However, I was wondering if it’s possible to do without any extra files. Here’s what I have so far:

n=10;
for i in `seq 1 1 $n`; do
    echo "for a$i in {a..b}; do ";
done;
echo -n "echo ";
for i in `seq 1 1 $n`; do
    echo -n '$'"a$i"; done;
    echo;
for i in `seq 1 1 $n`; do
    echo "done;";
done

(I formatted the code for readability, but it’s actually all on one line run from a prompt)

This gives me the following output:

for a1 in {a..b}; do 
for a2 in {a..b}; do 
for a3 in {a..b}; do 
for a4 in {a..b}; do 
for a5 in {a..b}; do 
for a6 in {a..b}; do 
for a7 in {a..b}; do 
for a8 in {a..b}; do 
for a9 in {a..b}; do 
for a10 in {a..b}; do 
echo $a1$a2$a3$a4$a5$a6$a7$a8$a9$a10
done;
done;
done;
done;
done;
done;
done;
done;
done;
done;

which is just fine. If I copy that and paste it back on the command line, it works like a charm and gives me the result.

The question is how do I do this with just the initial script, without copy-pasting and without redirecting anything to files.

I’ve tried sticking $( ) around the script, but that gives me “No command ‘for’ found'”, since it’s not really a command but a bash builtin. I’ve tried putting eval somewhere before this, but I just keep getting more errors. I’m a bit stuck, so any help would be greatly appreciated.

(Btw, just to reiterate, I’m doing this more or less to just learn bash more — that’s why I don’t want to redirect the output to a file and then execute that file. I know how to do that part, but I don’t know how to just do it from command line)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:12:27+00:00Added an answer on May 20, 2026 at 3:12 am

    You need to use an eval, $() gives you a string.

    eval $( echo echo foo )
    

    Another option is to stick into a subshell and pipe it to a bash:

    (echo echo foo) | /bin/bash
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.