Questions tagged [expansion]

428 questions
208
votes
6 answers

Base64: What is the worst possible increase in space usage?

If a server received a base64 string and wanted to check it's length before converting,, say it wanted to always permit the final byte array to be 16KB. How big could a 16KB byte array possibly become when converted to a Base64 string (assuming one…
700 Software
  • 85,281
  • 83
  • 234
  • 341
48
votes
3 answers

Why does shell ignore quoting characters in arguments passed to it through variables?

These work as advertised: grep -ir 'hello world' . grep -ir hello\ world . These don't: argumentString1="-ir 'hello world'" argumentString2="-ir hello\\ world" grep $argumentString1 . grep $argumentString2 . Despite 'hello world' being enclosed by…
Ben Wilhelm
  • 1,898
  • 3
  • 15
  • 12
39
votes
3 answers

how to make bash expand wildcards in variables?

I am trying achieve the same effect as typing mv ./images/*.{pdf,eps,jpg,svg} ./images/junk/ at the command line, from inside a bash script. I have: MYDIR="./images" OTHERDIR="./images/junk" SUFFIXES='{pdf,eps,jpg,svg}' mv "$MYDIR/"*.$SUFFIXES…
Ross Duncan
  • 610
  • 1
  • 5
  • 11
38
votes
4 answers

How to iterate through string one word at a time in zsh

How do I modify the following code so that when run in zsh it expands $things and iterates through them one at a time? things="one two" for one_thing in $things; do echo $one_thing done I want the output to be: one two But as written above,…
Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
32
votes
7 answers

Is it possible for C preprocessor macros to contain preprocessor directives?

I would like to do the equivalent of the following: #define print_max(TYPE) \ # ifdef TYPE##_MAX \ printf("%lld\n", TYPE##_MAX); \ # endif print_max(INT); Now the #ifdef or any nested preprocessor directive is not allowed as far as I can…
pixelbeat
  • 30,615
  • 9
  • 51
  • 60
26
votes
5 answers

Curious C# using statement expansion

I've run ildasm to find that this: using(Simple simp = new Simple()) { Console.WriteLine("here"); } generates IL code that is equivalent to this: Simple simp = new Simple(); try { Console.WriteLine("here"); …
Matthew
  • 261
  • 3
  • 3
25
votes
3 answers

Four Dollar signs in Makefile

I am reading the document of GNU Make. Here is an example %.d: %.c @set -e; rm -f $@; \ $(CC) -M $(CPPFLAGS) $< > $@.$$$$; \ sed ’s,\($*\)\.o[ :]*,\1.o $@ : ,g’ < $@.$$$$ > $@; \ rm -f $@.$$$$ I tried this on a C++ program,…
Tim
  • 1
  • 141
  • 372
  • 590
24
votes
3 answers

bash variable expansion ${var:+"..."} in here-document removing double quotes?

I'm trying to understand why Bash removes double quotes (but not single quotes) when doing variable expansion with ${parameter:+word} (Use Alternate Value), in a here-document, for example: % var=1 % cat < ${var:+"Hi there"} > ${var:+'Bye'} >…
Andreas Luik
  • 241
  • 1
  • 4
23
votes
3 answers

Why $'\0' or $'\x0' is an empty string? Should be the null-character, isn't it?

bash allows $'string' expansion. My man bash says: Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if…
oHo
  • 51,447
  • 27
  • 165
  • 200
22
votes
8 answers

Globbing/pathname expansion with colon as separator

How can I convert a string containing glob characters such as /var/lib/gems/*/bin into a colon-separated string of filenames (i.e. PATH compatible) matching the pattern? i.e. echo /var/lib/gems/*/bin will return /var/lib/gems/1.8/bin…
mjs
  • 63,493
  • 27
  • 91
  • 122
21
votes
6 answers

Brace expansion in python glob

I have python 2.7 and am trying to issue: glob('{faint,bright*}/{science,calib}/chip?/') I obtain no matches, however from the shell echo {faint,bright*}/{science,calib}/chip? gives: faint/science/chip1 faint/science/chip2 faint/calib/chip1…
astabada
  • 1,029
  • 4
  • 13
  • 26
19
votes
5 answers

Gnuwin32 find.exe expands wildcard before performing search

I am using Gnuwin32 binaries on a Windows environment. When I want to find files of a certain type, let's say PDF, I usually run: find . -iname '*.pdf' -print This works perfectly on any UNIX system. find.exe . -iname "*.pdf" -print But under…
Benoit
  • 76,634
  • 23
  • 210
  • 236
18
votes
4 answers

Why zsh tries to expand * and bash does not?

I just encountered the following error with zsh when trying to use logcat. Namely, when typing: adb logcat *:D I get the following error in zsh zsh: no matches found: *:D I have to escape the * like : adb logcat \*:D While using bash, I do…
Patryk
  • 22,602
  • 44
  • 128
  • 244
17
votes
2 answers

android - so many problems with the expansion library

i need to use the new google-play (or market) expansion library , and i have hard time with it . i wonder if anyone else is using it and notice the same problems i can see , so i would be very happy if you could help be to fix them: 1.sometimes i…
android developer
  • 114,585
  • 152
  • 739
  • 1,270
17
votes
4 answers

bash tab completion without variable expansion?

Let's say I have these variables defined in my bashrc: i='cgi-bin/internal'; e='cgi-bin/external'; f='cgi-bin/foo'; b='cgi-bin/bar'; ad='cgi-bin/admin'; #etc... When I use the variable on the command line vim $i/edit_TAB it will expand…
Andrew Sohn
  • 675
  • 1
  • 6
  • 15
1
2 3
28 29