Vi um comando interessante, mas não é possível alias

3

Vi um comando deste post link que gostaria de usar como alias

find {,/usr}/{,s}bin -printf '%f
alias cccc='find {,/usr}/{,s}bin -printf '%f
    pell0modem-manager0airserv-ng0usermod0vipw0filefrag0update-software-center0ntpdate-
debian0usbmuxd0foomatic-extract-text0cupsenable0dpkg-divert0dpkg-preconfigure0foomatic-
getpjloptions0ldattach0hplj10200bccmd0vpnc-disconnect0madwifi-
unload0cupsd0tcpd0hplj10180pppstats0service0update-icon-caches0atieventsd0hpljP15050grub-
set-default0userdel0arpd0gpsdctl0remove-shell0cpgr0winbindd0cracklib-format0update-catalog0wesside-ng0vmware-authdlauncher0aireplay-ng0install-docs0hciattach0lpc0install-menu0ck-log-system-restart0foomatic-printermap-to-gutenprint-xml0setvesablank0gconf-schemas0airmon-ng0zic0update-apt-xapian-index0pm-suspend0rebuild-
' | xargs -0 whatis | sort | less' cccc
' | xargs -0 whatis | sort | less

Eu assumo que o less ou o | está interferindo, mas como posso fazer o comando alias ignorar os caracteres que estão causando problemas?

ie. Isso não funciona

[ (1)                - check file types and compare values
2to3 (1)             - Python2 to Python3 converter
2to3-2.7 (1)         - Python2 to Python3 converter
2to3-3.2 (1)         - Python2 to Python3 converter
411toppm (1)         - convert Sony Mavica .411 image to ppm
7z (1)               - A file archiver with highest compression ratio
7za (1)              - A file archiver with highest compression ratio
a2p (1)              - Awk to Perl translator
accept (2)           - accept a connection on a socket
accessdb (8)         - dumps the content of a man-db database in a human read...
aclocal-1.11 (1)     - manual page for aclocal 1.11.6
aclocal (1)          - manual page for aclocal 1.11.3

Retorna

fff() { 
   find {,/usr}/{,s}bin -printf '%f
pdfunite (1)         - Portable Document Format (PDF) page merger
ps2pdf13 (1)         - Convert PostScript to PDF 1.3 (Acrobat 4-and-later com...
pdftotext (1)        - Portable Document Format (PDF) to text converter (vers...
ps2pdfwr (1)         - Convert PostScript to PDF without specifying Compatibi...
pdfdetach (1)        - Portable Document Format (PDF) document embedded file ...
ps2pdf (1)           - Convert PostScript to PDF using ghostscript
ps2pdf12 (1)         - Convert PostScript to PDF 1.2 (Acrobat 3-and-later com...
pdf2dsc (1)          - generate a PostScript page list of a PDF document
pdfimages (1)        - Portable Document Format (PDF) image extractor (versio...
pdftoppm (1)         - Portable Document Format (PDF) to Portable Pixmap (PPM...
foomatic-ppdfile (1) - Generate a PPD file for a given printer/driver combo
dvipdf (1)           - Convert TeX DVI file to PDF using ghostscript and dvips
qpdf (1)             - PDF transformation software
pdftocairo (1)       - Portable Document Format (PDF) to PNG/JPEG/PDF/PS/EPS/...
pdfseparate (1)      - Portable Document Format (PDF) page extractor
pdftops (1)          - Portable Document Format (PDF) to PostScript converter...
ps2pdf14 (1)         - Convert PostScript to PDF 1.4 (Acrobat 5-and-later com...
pdfinfo (1)          - Portable Document Format (PDF) document information ex...
pdftohtml (1)        - program to convert PDF files into HTML, XML and PNG im...
pdfopt (1)           - Ghostscript PDF Optimizer
pdffonts (1)         - Portable Document Format (PDF) font analyzer (version ...
pdf2ps (1)           - Ghostscript PDF to PostScript translator
' | xargs -0 whatis |& grep $1 }

Em vez de

find {,/usr}/{,s}bin -printf '%f
alias cccc='find {,/usr}/{,s}bin -printf '%f
    pell0modem-manager0airserv-ng0usermod0vipw0filefrag0update-software-center0ntpdate-
debian0usbmuxd0foomatic-extract-text0cupsenable0dpkg-divert0dpkg-preconfigure0foomatic-
getpjloptions0ldattach0hplj10200bccmd0vpnc-disconnect0madwifi-
unload0cupsd0tcpd0hplj10180pppstats0service0update-icon-caches0atieventsd0hpljP15050grub-
set-default0userdel0arpd0gpsdctl0remove-shell0cpgr0winbindd0cracklib-format0update-catalog0wesside-ng0vmware-authdlauncher0aireplay-ng0install-docs0hciattach0lpc0install-menu0ck-log-system-restart0foomatic-printermap-to-gutenprint-xml0setvesablank0gconf-schemas0airmon-ng0zic0update-apt-xapian-index0pm-suspend0rebuild-
' | xargs -0 whatis | sort | less' cccc
' | xargs -0 whatis | sort | less

quando você executa o comando sozinho.

After the Fact - Supplemental


I also added another useful function for myself to query via a string against that catalogue of commands.
[ (1)                - check file types and compare values
2to3 (1)             - Python2 to Python3 converter
2to3-2.7 (1)         - Python2 to Python3 converter
2to3-3.2 (1)         - Python2 to Python3 converter
411toppm (1)         - convert Sony Mavica .411 image to ppm
7z (1)               - A file archiver with highest compression ratio
7za (1)              - A file archiver with highest compression ratio
a2p (1)              - Awk to Perl translator
accept (2)           - accept a connection on a socket
accessdb (8)         - dumps the content of a man-db database in a human read...
aclocal-1.11 (1)     - manual page for aclocal 1.11.6
aclocal (1)          - manual page for aclocal 1.11.3

Então, se você digitar o comando fff pdf , ele mostrará todos os comandos relacionados sobre o pdf como este

fff() { 
   find {,/usr}/{,s}bin -printf '%f
pdfunite (1)         - Portable Document Format (PDF) page merger
ps2pdf13 (1)         - Convert PostScript to PDF 1.3 (Acrobat 4-and-later com...
pdftotext (1)        - Portable Document Format (PDF) to text converter (vers...
ps2pdfwr (1)         - Convert PostScript to PDF without specifying Compatibi...
pdfdetach (1)        - Portable Document Format (PDF) document embedded file ...
ps2pdf (1)           - Convert PostScript to PDF using ghostscript
ps2pdf12 (1)         - Convert PostScript to PDF 1.2 (Acrobat 3-and-later com...
pdf2dsc (1)          - generate a PostScript page list of a PDF document
pdfimages (1)        - Portable Document Format (PDF) image extractor (versio...
pdftoppm (1)         - Portable Document Format (PDF) to Portable Pixmap (PPM...
foomatic-ppdfile (1) - Generate a PPD file for a given printer/driver combo
dvipdf (1)           - Convert TeX DVI file to PDF using ghostscript and dvips
qpdf (1)             - PDF transformation software
pdftocairo (1)       - Portable Document Format (PDF) to PNG/JPEG/PDF/PS/EPS/...
pdfseparate (1)      - Portable Document Format (PDF) page extractor
pdftops (1)          - Portable Document Format (PDF) to PostScript converter...
ps2pdf14 (1)         - Convert PostScript to PDF 1.4 (Acrobat 5-and-later com...
pdfinfo (1)          - Portable Document Format (PDF) document information ex...
pdftohtml (1)        - program to convert PDF files into HTML, XML and PNG im...
pdfopt (1)           - Ghostscript PDF Optimizer
pdffonts (1)         - Portable Document Format (PDF) font analyzer (version ...
pdf2ps (1)           - Ghostscript PDF to PostScript translator
' | xargs -0 whatis |& grep $1 }

Acho que isso é útil para conhecer todos os comandos disponíveis

    
por Meer Borg 12.03.2013 / 09:17

1 resposta

7

Não se preocupe com aliases para coisas mais complicadas, use uma função de shell:

 function cccc() {
    find {,/usr}/{,s}bin -printf '%f
 function cccc() {
    find {,/usr}/{,s}bin -printf '%f%pre%' | xargs -0 whatis | sort | less
 }
' | xargs -0 whatis | sort | less }

Veja man bash para a justificativa:

The rules concerning the definition and use of aliases are somewhat confusing. Bash always reads at least one complete line of input before executing any of the commands on that line. Aliases are expanded when a command is read, not when it is executed. Therefore, an alias definition appearing on the same line as another command does not take effect until the next line of input is read. The commands following the alias definition on that line are not affected by the new alias. This behavior is also an issue when functions are executed. Aliases are expanded when a function definition is read, not when the function is executed, because a function definition is itself a compound command. As a consequence, aliases defined in a function are not available until after that function is executed. To be safe, always put alias definitions on a separate line, and do not use alias in compound commands.

    
por H.-Dirk Schmitt 12.03.2013 / 09:22