Skip to content

Commit 28a9f13

Browse files
committed
Document how to use run with <>
Also slightly discourage «», and add a separate section to traps about «». It is somewhat copypasted but that's ok, as having a separate section in traps raises awareness without requiring to read all of the docs. Resolves #1745 and makes me happy.
1 parent 1b723a2 commit 28a9f13

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

doc/Language/traps.pod6

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,25 @@ The bottom line is that C<map> and C<»> are not interchangeable, but
12321232
using one instead of the other is OK as long as you understand the
12331233
differences.
12341234
1235+
=head2 Word splitting in C<« »>
1236+
1237+
Keep in mind that C<« »> performs word splitting similarly to how
1238+
shells do it, so
1239+
L<many shell pitfalls|http://mywiki.wooledge.org/BashPitfalls> apply
1240+
here as well (especially when using in combination with C<run>):
1241+
1242+
my $file = ‘--my arbitrary filename’;
1243+
run ‘touch’, ‘--’, $file; # RIGHT
1244+
run <touch -->, $file; # RIGHT
1245+
1246+
run «touch -- "$file"»; # RIGHT but WRONG if you forget quotes
1247+
run «touch -- $file»; # WRONG; touches ‘--my’, ‘arbitrary’ and ‘filename’
1248+
run ‘touch’, $file; # WRONG; error from `touch`
1249+
run «touch "$file"»; # WRONG; error from `touch`
1250+
1251+
Note that C<--> is required to make it work for
1252+
L<filenames with leading dashes|http://mywiki.wooledge.org/BashPitfalls#Filenames_with_leading_dashes>.
1253+
12351254
=head1 Scope
12361255
12371256
=head2 Using a C<once> block

doc/Type/IO.pod6

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,24 @@ Runs an external command without involving a shell and returns a L<Proc> object.
339339
340340
run 'touch', '>foo.txt'; # Create a file named >foo.txt
341341
342-
run Q:w{rm >foo.txt}; # Another way to use run, using word quoting for the
343-
# arguments
342+
run <rm >foo.txt>; # Another way to use run, using word quoting for the
343+
# arguments
344+
345+
If you want to pass some variables you can still use C«< >», but try
346+
to avoid using C<« »> as it will do word splitting if you forget to
347+
quote variables:
348+
349+
my $file = ‘--my arbitrary filename’;
350+
run ‘touch’, ‘--’, $file; # RIGHT
351+
run <touch -->, $file; # RIGHT
352+
353+
run «touch -- "$file"»; # RIGHT but WRONG if you forget quotes
354+
run «touch -- $file»; # WRONG; touches ‘--my’, ‘arbitrary’ and ‘filename’
355+
run ‘touch’, $file; # WRONG; error from `touch`
356+
run «touch "$file"»; # WRONG; error from `touch`
357+
358+
Note that C<--> is required to make it work for
359+
L<filenames with leading dashes|http://mywiki.wooledge.org/BashPitfalls#Filenames_with_leading_dashes>.
344360
345361
A sunk L<Proc> object for a process that L<exited|/routine/exitcode> unsuccessfully
346362
will throw. If you wish to ignore such failures, simply use L<run> in non-sink context:

0 commit comments

Comments
 (0)