3 ms·
Better: $ touch 'j-kidd'\''s file!' $ ll 'j-kidd'\''s file!' -rw-rw-r-- 1 uid gid 0 Apr 11 13:30 j-kidd's file! History expansion will happen on the ! i
by pyre 14y ago
Better:
$ touch 'j-kidd'\''s file!'
$ ll 'j-kidd'\''s file!'
-rw-rw-r-- 1 uid gid 0 Apr 11 13:30 j-kidd's file!
History expansion will happen on the ! in double quotes:
$ ls "!$"
ls "'j-kidd'\''s file!'"
ls: cannot access 'j-kidd'\''s file!': No such file or directory
It won't happen on single-quotes:
$ ls '!$'
ls: cannot access !$: No such file or directory
The only issue is that you can't escape a single-quote within single quotes, so you have to do one of these '\'' (escape a single-quote block, a literal single quote, start a new single quote block).
- qb45 14y agoYep, that's an important and maybe non-obvious behavior of the shell: "directly adjacent strings which are double quoted, "'single quoted or even'\ unquoted\ and\ possibly\ full\ of\ escape\ sequences\ 'get concatenated and count as a single parameter.' Running touch on the above will create one file with very long name.