Skip to main content
A few typos were removed, and grammar was slightly improved.
Source Link

Or,… or an introductory guide to robust filename handling and other string passing in shell scripts.

I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some file names).

I encountered a problem such as the following:

  • I have a file name containing a space hello world, and it was treated as two separate files hello and world.
  • I have an input line with two consecutive spaces and they shrank to one in the input.
  • Leading and trailing whitespace disappears from input lines.
  • Sometimes, when the input contains one of the characters \[*?, they are replaced replaced by some text which is is actually the namenames of some files.
  • There is an apostrophe ' (or a double quote ") in the input, and things got weird after that point.
  • There is a backslash in the input (or: I am using Cygwin and some of my file names have Windows-style \ separators).

What is going on, and how do I fix itthis?

Or, an introductory guide to robust filename handling and other string passing in shell scripts.

I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some file names).

I encountered a problem such as the following:

  • I have a file name containing a space hello world, and it was treated as two separate files hello and world.
  • I have an input line with two consecutive spaces and they shrank to one in the input.
  • Leading and trailing whitespace disappears from input lines.
  • Sometimes, when the input contains one of the characters \[*?, they are replaced by some text which is is actually the name of files.
  • There is an apostrophe ' (or a double quote ") in the input and things got weird after that point.
  • There is a backslash in the input (or: I am using Cygwin and some of my file names have Windows-style \ separators).

What is going on and how do I fix it?

… or an introductory guide to robust filename handling and other string passing in shell scripts.

I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some file names).

I encountered a problem such as the following:

  • I have a file name containing a space hello world, and it was treated as two separate files hello and world.
  • I have an input line with two consecutive spaces and they shrank to one in the input.
  • Leading and trailing whitespace disappears from input lines.
  • Sometimes, when the input contains one of the characters \[*?, they are replaced by some text which is actually the names of some files.
  • There is an apostrophe ' (or a double quote ") in the input, and things got weird after that point.
  • There is a backslash in the input (or: I am using Cygwin and some of my file names have Windows-style \ separators).

What is going on, and how do I fix this?

Question Protected by CommunityBot
Removed un-needed new-lines.
Source Link
user79743
user79743

Or, an introductory guide to robust filename handling and other string passing in in shell scripts.

I wrote a shell script which works well most of the time. But it chokes on some inputs inputs (e.g. on some file names).

I encountered a problem such as the following following:

  • I have a file name containing a space hello world, and it was treated as two separate separate files hello and world.
  • I have an input line with two consecutive spaces and they shrank to one in the input input.
  • Leading and trailing whitespace disappears from input lines.
  • Sometimes, when the input contains one of the characters \[*?, they are replaced by some text which is is actually the name of files.
  • There is an apostrophe ' (or a double quote ") in the input and things got weird weird after that point.
  • There is a backslash in the input (or: I am using Cygwin and some of my file names names have Windows-style \ separators).

What is going on and how do I fix it?

Or, an introductory guide to robust filename handling and other string passing in shell scripts.

I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some file names) I encountered a problem such as the following:

  • I have a file name containing a space hello world, and it was treated as two separate files hello and world.
  • I have an input line with two consecutive spaces and they shrank to one in the input.
  • Leading and trailing whitespace disappears from input lines.
  • Sometimes, when the input contains one of the characters \[*?, they are replaced by some text which is is actually the name of files.
  • There is an apostrophe ' (or a double quote ") in the input and things got weird after that point.
  • There is a backslash in the input (or: I am using Cygwin and some of my file names have Windows-style \ separators).

What is going on and how do I fix it?

Or, an introductory guide to robust filename handling and other string passing in shell scripts.

I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some file names).

I encountered a problem such as the following:

  • I have a file name containing a space hello world, and it was treated as two separate files hello and world.
  • I have an input line with two consecutive spaces and they shrank to one in the input.
  • Leading and trailing whitespace disappears from input lines.
  • Sometimes, when the input contains one of the characters \[*?, they are replaced by some text which is is actually the name of files.
  • There is an apostrophe ' (or a double quote ") in the input and things got weird after that point.
  • There is a backslash in the input (or: I am using Cygwin and some of my file names have Windows-style \ separators).

What is going on and how do I fix it?

Or, an introductory guide to robust filename handling and other string passing in in shell scripts.

I wrote a shell script which works well most of the time. But it chokes on some inputs inputs (e.g. on some file names) — I encountered a problem such as the following following:

  • I have a file name containing a space hello world, and it was treated as two separate separate files hello and world.
  • I have an input line with two consecutive spaces and they shrank to one in the input input.
  • Leading and trailing whitespace disappears from input lines.
  • Sometimes, when the input contains one of the characters \[*?, they're replacedthey are replaced by some text which is is actually the name of files.
  • There'sThere is an apostrophe ' (or a double quote ") in the input and things got weird weird after that point.
  • There'sThere is a backslash in the input (or: I'mI am using Cygwin and some of my file names names have Windows-style \ separators).

What'sWhat is going on and how do I fix it?

Or, an introductory guide to robust filename handling and other string passing in shell scripts.

I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some file names) — I encountered a problem such as the following:

  • I have a file name containing a space hello world, and it was treated as two separate files hello and world.
  • I have an input line with two consecutive spaces and they shrank to one in the input.
  • Leading and trailing whitespace disappears from input lines.
  • Sometimes, when the input contains one of the characters \[*?, they're replaced by some text which is is actually the name of files.
  • There's an apostrophe ' (or a double quote ") in the input and things got weird after that point.
  • There's a backslash in the input (or: I'm using Cygwin and some of my file names have Windows-style \ separators).

What's going on and how do I fix it?

Or, an introductory guide to robust filename handling and other string passing in shell scripts.

I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some file names) — I encountered a problem such as the following:

  • I have a file name containing a space hello world, and it was treated as two separate files hello and world.
  • I have an input line with two consecutive spaces and they shrank to one in the input.
  • Leading and trailing whitespace disappears from input lines.
  • Sometimes, when the input contains one of the characters \[*?, they are replaced by some text which is is actually the name of files.
  • There is an apostrophe ' (or a double quote ") in the input and things got weird after that point.
  • There is a backslash in the input (or: I am using Cygwin and some of my file names have Windows-style \ separators).

What is going on and how do I fix it?

Tweeted twitter.com/#!/StackUnix/status/470059127142883328
Source Link
Gilles 'SO- stop being evil'
  • 865.9k
  • 205
  • 1.8k
  • 2.3k
Loading