Skip to main content
added 6 characters in body
Source Link
Stéphane Chazelas
  • 586.8k
  • 96
  • 1.1k
  • 1.7k

The

rm "$OUTPUT/*.gz"

shell command line tells the shell to execute /bin/rm with with two arguments: rm and /path/to/backup/files/*.gz.

The space, " and $ are special characters in the shell language syntax. Space is used to delimit command arguments, " is used to quote other special characters (not all, $ for instance is still special) like that * above, and $ is used for some expansions (like the $OUTPUT parameter expansion that you're using here).

rm once started will try to remove that /path/to/backup/files/*.gz file. If that file doesn't exist (as is the case for you), it will report an error.

When you write:

rm /path/to/backup/files/*.gz

or

rm "$OUTPUT"/*.gz

Since * is not quoted this time, it triggers another special feature of the shell called globbingglobbing or filename generationfilename generation or filename expansionpathname expansion. The shell tries to expand the word that contains that * character to the list of file names that match the pattern.

So if /path/to/backup/files contains a a.gz and b.gz files, the shell will actually call rm with 3 arguments: rm, /path/to/backup/files/a.gz and /path/to/backup/files/b.gz which looks more like what you want here.

Note that $OUTPUT itself still needs to be quoted as otherwise it could end up being split if it contains characters of $IFS or also be subject to globbing if it contained any wildcard characters (like that * above).

It's also a good idea to get used to writing:

rm -- "$OUTPUT"/*.gz

Here $OUTPUT happens to start with /, so it's fine, but the day you change $OUTPUT to -foo- for instance, it will stop working as that -foo-/... would be taken by rm as options.

If the script is not meant to be interactive, you may want to add the -f option to rm. That will disable all user prompts, and remove the error if there's no matching file (mostmany shells, when a glob has no match, pass the pattern as-is to the application, and rm -f doesn't complain when asked to remove a file that doesn't exist in the first place).

The

rm "$OUTPUT/*.gz"

shell command line tells the shell to execute /bin/rm with with two arguments: rm and /path/to/backup/files/*.gz.

The space, " and $ are special characters in the shell language syntax. Space is used to delimit command arguments, " is used to quote other special characters (not all, $ for instance is still special) like that * above, and $ is used for some expansions (like the $OUTPUT parameter expansion that you're using here).

rm once started will try to remove that /path/to/backup/files/*.gz file. If that file doesn't exist (as is the case for you), it will report an error.

When you write:

rm /path/to/backup/files/*.gz

or

rm "$OUTPUT"/*.gz

Since * is not quoted this time, it triggers another special feature of the shell called globbing or filename generation or filename expansion. The shell tries to expand the word that contains that * character to the list of file names that match the pattern.

So if /path/to/backup/files contains a a.gz and b.gz files, the shell will actually call rm with 3 arguments: rm, /path/to/backup/files/a.gz and /path/to/backup/files/b.gz which looks more like what you want here.

Note that $OUTPUT itself still needs to be quoted as otherwise it could end up being split if it contains characters of $IFS or also be subject to globbing if it contained any wildcard characters (like that * above).

It's also a good idea to get used to writing:

rm -- "$OUTPUT"/*.gz

Here $OUTPUT happens to start with /, so it's fine, but the day you change $OUTPUT to -foo- for instance, it will stop working as that -foo-/... would be taken by rm as options.

If the script is not meant to be interactive, you may want to add the -f option to rm. That will disable all user prompts, and remove the error if there's no matching file (most shells, when a glob has no match, pass the pattern as-is to the application, and rm -f doesn't complain when asked to remove a file that doesn't exist in the first place).

The

rm "$OUTPUT/*.gz"

shell command line tells the shell to execute /bin/rm with with two arguments: rm and /path/to/backup/files/*.gz.

The space, " and $ are special characters in the shell language syntax. Space is used to delimit command arguments, " is used to quote other special characters (not all, $ for instance is still special) like that * above, and $ is used for some expansions (like the $OUTPUT parameter expansion that you're using here).

rm once started will try to remove that /path/to/backup/files/*.gz file. If that file doesn't exist (as is the case for you), it will report an error.

When you write:

rm /path/to/backup/files/*.gz

or

rm "$OUTPUT"/*.gz

Since * is not quoted this time, it triggers another special feature of the shell called globbing or filename generation or pathname expansion. The shell tries to expand the word that contains that * character to the list of file names that match the pattern.

So if /path/to/backup/files contains a a.gz and b.gz files, the shell will actually call rm with 3 arguments: rm, /path/to/backup/files/a.gz and /path/to/backup/files/b.gz which looks more like what you want here.

Note that $OUTPUT itself still needs to be quoted as otherwise it could end up being split if it contains characters of $IFS or also be subject to globbing if it contained any wildcard characters (like that * above).

It's also a good idea to get used to writing:

rm -- "$OUTPUT"/*.gz

Here $OUTPUT happens to start with /, so it's fine, but the day you change $OUTPUT to -foo- for instance, it will stop working as that -foo-/... would be taken by rm as options.

If the script is not meant to be interactive, you may want to add the -f option to rm. That will disable all user prompts, and remove the error if there's no matching file (many shells, when a glob has no match, pass the pattern as-is to the application, and rm -f doesn't complain when asked to remove a file that doesn't exist in the first place).

added 801 characters in body
Source Link
Stéphane Chazelas
  • 586.8k
  • 96
  • 1.1k
  • 1.7k

The

rm "$OUTPUT/*.gz"

shell command line tells the shell to execute /bin/rm with with two arguments: rm and /path/to/backup/files/*.gz.

The space, " and $ are special characters in the shell language syntax. Space is used to delimit command arguments, " is used to quote other special characters (not all, $ for instance is still special) like that *above, and*$ above, and is used for some expansions (like the$$OUTPUT` is used for some expansions (like the $OUTPUT parameter expansion that you're using here).

rm once started will try to remove that /path/to/backup/files/*.gz file. If that file doesn't exist (as is the case for you), it will report an error.

When you write:

rm /path/to/backup/files/*.gz

or

rm "$OUTPUT"/*.gz

Since * is not quoted this time, it triggers another special feature of the shell called globbing or filename generation or filename expansion. The shell tries to expand the word that contains that * character to the list of file names that match the pattern.

So if /path/to/backup/files countainscontains a a.gz and b.gz files, the shell will actually call rm with 3 arguments: rm, /path/to/backup/files/a.gz and /path/to/backup/files/b.gz which looks more like what you want here.

Note that $OUTPUT itself still needs to be quoted as otherwise it could end up being split if it contains characters of $IFS or also be subject to globbing if it contained any wildcard characters (like that * above).

It's also a good idea to get used to writing:

rm -- "$OUTPUT"/*.gz

Here $OUTPUT happens to start with /, so it's fine, but the day you change $OUTPUT to -foo- for instance, it will stop working as that -foo-/... would be taken by rm as options.

If the script is not meant to be interactive, you may want to add the -f option to rm. That will disable all user prompts, and remove the error if there's no matching file (most shells, when a glob has no match, pass the pattern as-is to the application, and rm -f doesn't complain when asked to remove a file that doesn't exist in the first place).

The

rm "$OUTPUT/*.gz"

shell command line tells the shell to execute /bin/rm with with two arguments: rm and /path/to/backup/files/*.gz.

The space, " and $ are special characters in the shell language syntax. Space is used to delimit command arguments, " is used to quote other special characters (not all, $ for instance is still special) like that *above, and$is used for some expansions (like the$OUTPUT` parameter expansion that you're using here.

rm once started will try to remove that /path/to/backup/files/*.gz file. If that file doesn't exist (as is the case for you), it will report an error.

When you write:

rm /path/to/backup/files/*.gz

or

rm "$OUTPUT"/*.gz

Since * is not quoted, it triggers another special feature of the shell called globbing or filename expansion. The shell tries to expand the word that contains that * character to the list of file names that match the pattern.

So if /path/to/backup/files countains a a.gz and b.gz files, the shell will actually call rm with 3 arguments: rm, /path/to/backup/files/a.gz and /path/to/backup/files/b.gz which looks more like what you want here.

The

rm "$OUTPUT/*.gz"

shell command line tells the shell to execute /bin/rm with with two arguments: rm and /path/to/backup/files/*.gz.

The space, " and $ are special characters in the shell language syntax. Space is used to delimit command arguments, " is used to quote other special characters (not all, $ for instance is still special) like that * above, and $ is used for some expansions (like the $OUTPUT parameter expansion that you're using here).

rm once started will try to remove that /path/to/backup/files/*.gz file. If that file doesn't exist (as is the case for you), it will report an error.

When you write:

rm /path/to/backup/files/*.gz

or

rm "$OUTPUT"/*.gz

Since * is not quoted this time, it triggers another special feature of the shell called globbing or filename generation or filename expansion. The shell tries to expand the word that contains that * character to the list of file names that match the pattern.

So if /path/to/backup/files contains a a.gz and b.gz files, the shell will actually call rm with 3 arguments: rm, /path/to/backup/files/a.gz and /path/to/backup/files/b.gz which looks more like what you want here.

Note that $OUTPUT itself still needs to be quoted as otherwise it could end up being split if it contains characters of $IFS or also be subject to globbing if it contained any wildcard characters (like that * above).

It's also a good idea to get used to writing:

rm -- "$OUTPUT"/*.gz

Here $OUTPUT happens to start with /, so it's fine, but the day you change $OUTPUT to -foo- for instance, it will stop working as that -foo-/... would be taken by rm as options.

If the script is not meant to be interactive, you may want to add the -f option to rm. That will disable all user prompts, and remove the error if there's no matching file (most shells, when a glob has no match, pass the pattern as-is to the application, and rm -f doesn't complain when asked to remove a file that doesn't exist in the first place).

Source Link
Stéphane Chazelas
  • 586.8k
  • 96
  • 1.1k
  • 1.7k

The

rm "$OUTPUT/*.gz"

shell command line tells the shell to execute /bin/rm with with two arguments: rm and /path/to/backup/files/*.gz.

The space, " and $ are special characters in the shell language syntax. Space is used to delimit command arguments, " is used to quote other special characters (not all, $ for instance is still special) like that *above, and$is used for some expansions (like the$OUTPUT` parameter expansion that you're using here.

rm once started will try to remove that /path/to/backup/files/*.gz file. If that file doesn't exist (as is the case for you), it will report an error.

When you write:

rm /path/to/backup/files/*.gz

or

rm "$OUTPUT"/*.gz

Since * is not quoted, it triggers another special feature of the shell called globbing or filename expansion. The shell tries to expand the word that contains that * character to the list of file names that match the pattern.

So if /path/to/backup/files countains a a.gz and b.gz files, the shell will actually call rm with 3 arguments: rm, /path/to/backup/files/a.gz and /path/to/backup/files/b.gz which looks more like what you want here.