How can I suppress the space between generated arguments during brace expansion?

iconoclast

I used the following command to create a list of URLs that I want to test:

echo -e localhost:8080/reports/{promos,promo-updates,scandown}/{130,139,142}{,-unburdened,-burdened}{,.pdf,.xls,.xlsx,.csv,.preload}"\n" >> urls.txt

Unfortunately the URLs appended to urls.txt each had a space before them (except for the first, of course). I understand why that happened, and I realize I could just strip it off by piping throug a sed expression, but I'd like to know if there's a way to suppress it instead. (It may seem silly and pedantic, but it's no different than the preference so many people feel for not "abusing cats".)

I tried double-quoting to suppress word-splitting, but that suppressed the brace expansion too, so that was a no-go.

I tried changing IFS to an empty string, but it didn't work either:

IFS='' echo -e localhost:8080/reports/{promos,promo-updates,scandown}/{130,139,142}{,-unburdened,-burdened}{,.pdf,.xls,.xlsx,.csv,.preload}"\n" >> urls.txt

Nor did changing it to a newline:

IFS='\n' echo -e localhost:8080/reports/{promos,promo-updates,scandown}/{130,139,142}{,-unburdened,-burdened}{,.pdf,.xls,.xlsx,.csv,.preload}"\n" >> urls.txt
glenn jackman

You could store the brace expansion in an array, then output it in the manner of your choosing:

urls=( localhost:8080/reports/{promos,promo-updates,scandown}/{130,139,142}{,-unburdened,-burdened}{,.pdf,.xls,.xlsx,.csv,.preload} )

Then

printf "%s\n" "${urls[@]}"

or

(IFS=$'\n'; echo "${urls[*]}")

The echo example looks weird because:

  1. it's run in a subshell (the parentheses) so I don't alter my current value of IFS.
  2. IFS needs to be defined in a separate command:
    • This doesn't work: IFS=$'\n' echo "${urls[*]}" because the variable gets expanded before the new env variable takes effect
    • IFS needs to be set before you start expanding variables.

Also, note the subtle difference in the dereferencing array index used:

  • [@] in the printf example to expand the array into individual words
  • [*] in the echo example to expand the array into a single word, with elements separated by the first char of IFS

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I do brace expansion on variables?

From Dev

How can I generate a list with brace expansion in a specific order?

From Dev

How can I generate a list with brace expansion in a specific order?

From Dev

How can I use $variable in a shell brace expansion of a sequence?

From Dev

How can I suppress warnings in generated code?

From Dev

Unwanted space in brace expansion

From Dev

Brace expansion with $@ arguments

From Dev

Can I use a variable in a Bash brace expansion?

From Dev

Can I use bash brace expansion in for loop?

From Dev

How can I suppress the "copying" window during FTP upload?

From Dev

How can I use a constexpr function during pack expansion?

From Dev

How does bash differentiate between brace expansion and command grouping?

From Dev

How do I copy files with curly brace expansion in the path?

From Dev

How do I get 0-padded numbers in {} (brace expansion)?

From Dev

how to use variables with brace expansion

From Dev

How to apply parameter expansion on brace expansion (range)?

From Dev

How can I suppress the JSHint "JSCS: Illegal Space" warnings in Visual Studio 2013?

From Dev

Can brace expansion be performed within the `at` command?

From Dev

Can't combine brace expansion with parameter expansion in bash

From Dev

How does curly brace expansion work in the shell?

From Dev

Brace expansion does not work for less than 2 arguments

From Dev

How do I get zero-padded numbers using brace expansion? {1..30} with 01 02 03 etc

From Dev

How do I suppress compiler warnings in Xcode for generated files?

From Dev

How Can I Suppress "Load Fallback Graphics Devices" and "Plymouth Upstart Bridge" Messages During Ubuntu Server 14.04 Boot-Up?

From Dev

How can I set a minimum amount of space between flexbox items?

From Dev

How can I add space between anchor tags?

From Dev

How can I remove the space between header and body in PDF report?

From Dev

Space between <td>. Why and how can I remove?

From Dev

how can I add a space between each consecutive pipes with sed

Related Related

  1. 1

    How can I do brace expansion on variables?

  2. 2

    How can I generate a list with brace expansion in a specific order?

  3. 3

    How can I generate a list with brace expansion in a specific order?

  4. 4

    How can I use $variable in a shell brace expansion of a sequence?

  5. 5

    How can I suppress warnings in generated code?

  6. 6

    Unwanted space in brace expansion

  7. 7

    Brace expansion with $@ arguments

  8. 8

    Can I use a variable in a Bash brace expansion?

  9. 9

    Can I use bash brace expansion in for loop?

  10. 10

    How can I suppress the "copying" window during FTP upload?

  11. 11

    How can I use a constexpr function during pack expansion?

  12. 12

    How does bash differentiate between brace expansion and command grouping?

  13. 13

    How do I copy files with curly brace expansion in the path?

  14. 14

    How do I get 0-padded numbers in {} (brace expansion)?

  15. 15

    how to use variables with brace expansion

  16. 16

    How to apply parameter expansion on brace expansion (range)?

  17. 17

    How can I suppress the JSHint "JSCS: Illegal Space" warnings in Visual Studio 2013?

  18. 18

    Can brace expansion be performed within the `at` command?

  19. 19

    Can't combine brace expansion with parameter expansion in bash

  20. 20

    How does curly brace expansion work in the shell?

  21. 21

    Brace expansion does not work for less than 2 arguments

  22. 22

    How do I get zero-padded numbers using brace expansion? {1..30} with 01 02 03 etc

  23. 23

    How do I suppress compiler warnings in Xcode for generated files?

  24. 24

    How Can I Suppress "Load Fallback Graphics Devices" and "Plymouth Upstart Bridge" Messages During Ubuntu Server 14.04 Boot-Up?

  25. 25

    How can I set a minimum amount of space between flexbox items?

  26. 26

    How can I add space between anchor tags?

  27. 27

    How can I remove the space between header and body in PDF report?

  28. 28

    Space between <td>. Why and how can I remove?

  29. 29

    how can I add a space between each consecutive pipes with sed

HotTag

Archive