in reply to Re^3: How to use the -T file op as a one-liner
in thread How to use the -T file op as a one-liner

"The problem I still have with the Perl one-liner is that I don't know how to embed the filename I want to query inside double quotes or how to escape the slash path separators so that it is not interpreted as a regex.
... I wanted a simple "text" or "binary" response ..."

You can just let Perl handle the embedding of filenames/pathnames for you; e.g.

$ pwd /home/ken/tmp $ perl -E 'say +(qw{binary text})[-T $ARGV[0]]' /usr/bin/perl binary $ perl -E 'say +(qw{binary text})[-T $ARGV[0]]' file_perl text $ perl -E 'say +(qw{binary text})[-T $ARGV[0]]' ./file_perl text $ perl -E 'say +(qw{binary text})[-T $ARGV[0]]' ~/tmp/file_perl text $ perl -E 'say +(qw{binary text})[-T $ARGV[0]]' ~ken/tmp/file_perl text $ perl -E 'say +(qw{binary text})[-T $ARGV[0]]' ../tmp/file_perl text $ perl -E 'say +(qw{binary text})[-T $ARGV[0]]' ../../../usr/bin/perl binary

Note that the commands are identical throughout. You can supply a filename or an absolute/relative pathname in whatever format you want (as an argument to that command).

In case you were wondering, file_perl still exists from earlier examples:

$ pwd /home/ken/tmp $ ls -l file_perl -rw-r--r-- 1 ken None 105 Aug 13 23:46 file_perl $ file file_perl file_perl: ASCII text $ cat file_perl /usr/bin/perl: PE32+ executable (console) x86-64 (stripped to external + PDB), for MS Windows, 11 sections

— Ken