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

  • SEARCH
  • Home
  • 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 8557311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:32:47+00:00 2026-06-11T15:32:47+00:00

I want to be able to let a user type in : ./script.sh server[01-10]type

  • 0

I want to be able to let a user type in :

./script.sh server[01-10]type

I have got this already working and works with [a-z] or [0-99] or however high numerically it goes. Although really unsure if I have gone about it all the right way and if there are easier ways of doing the same thing.

Wanted to check if there was an easier way of doing something like this and how easy it would be to have multiple wild card inputs like:

./script.sh (server|web)[01-10][a-z]

where it would then parse for either web01-10a-z or server01-10a-z and list all servers.

Here is what I have so far and admit I need to tidy it up but was thinking let me get it working better before focusing on tidier code calls.

 #!/bin/bash
 input=$1;
 if [[ $input =~ \[ ]];then
     s="["
     f="]"
     host_start=`echo $input|awk -F"[" '{print $1}'`
     host_end=`echo $input|awk -F"]" '{print $2}'`
     start=`awk -v a="$input" -v b="$s" 'BEGIN{print index(a,b)}'`
     fin=`awk -v a="$input" -v b="$f" 'BEGIN{print index(a,b)}'`
     vals=`expr $fin - $start`
     ((start++))
     ((vals--))
     in1=`echo $input| awk -v s=$start -v f=$vals '{ print substr( $0, s($0),f($0) ) }'`
     val1=`echo $in1|awk -F"\-" '{print $1}'`
     val2=`echo $in1|awk -F"\-" '{print $2}'`
     for index in $(eval echo {$val1..$val2})
     do
         server="$host_start$index$host_end"
         echo "Current server: $server "
     done
fi

When I execute this I get:

./run.bash apache[9-11]
Current server: apache9 
Current server: apache10 
Current server: apache11 

$ ./run.bash apache[f-k]
Current server: apachef 
Current server: apacheg 
Current server: apacheh 
Current server: apachei 
Current server: apachej 
Current server: apachek 

$ ./run.bash apache[f-k]abc
Current server: apachefabc 
Current server: apachegabc 
Current server: apachehabc 
Current server: apacheiabc 
Current server: apachejabc 
Current server: apachekabc 

UPDATED TO THANK EVERYONE

3 lines does all of above and handles all types I wanted here is how:

#!/bin/bash
val=$1;

value=`echo "$val"|sed 's:(:{:g; s:):}:g; s:|:,:g; s/^//;s/$//'`
value=`echo "$value"|sed 's:\[:{:g; s:\]:}:g; s:-:\.\.:g; s/^//;s/$//'`
(eval echo $value)

./test-brace.sh "(server|apache)[0-2][a-c]"
server0a server0b server0c server1a server1b server1c server2a server2b server2c apache0a apache0b apache0c apache1a apache1b apache1c apache2a apache2b apache2c
  • 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-06-11T15:32:48+00:00Added an answer on June 11, 2026 at 3:32 pm

    You don’t need a script. You just need brace expansion:

    echo {server,web}{01..10}{a..z}
    
    for s in {server,web}{01..10}{a..z}; do
        echo Current Server: $s
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to take an image that i have already captured
Let's say, I want the users to be able to customize the layout/format of
Let's assume that I have following models: class ScoutBook(models.Model): troop = models.ForeignKey('Dictionary', limit_choices_to={'type' :
Let's say I have a contentEditable div , to the user can edit and
I am using the OpenFileDialog to let the user choose a file. However, I
Let's say a user wants to delete a post and you want to perform
okay I have a dilemma. I am want to be able to upload a
I want to do something sort of like this: let x = 5 let
I'm using LaTeX and BibTeX for an article, and I want to able to
Want to be able to provide a search interface for a collection of objects

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.