Portál AbcLinuxu, 14. května 2025 20:08
mkfifo mypipe; cat Copy/sport.txt | tail -n 5 | cut -d"," -f1,2 >mypipe& [[ $(cat lesson4_task4.txt) == "ano" ]] && tr -s "[:upper:]" "[:lower:]" <mypipe >/dev/stdout || tr -s "[:lower:]" "[:upper:]" <mypipe >/dev/stdout; rm mypipea chtěl jsem se zeptat jak dosáhnout stejného výsledku bez pojmenované roury nebo dočasného souboru. Případně jak docílit toho aby přesměrování do souboru, teď do /dev/stdout se použilo jen jednou. Předem děkuji za odpovědi.
tail -n 5 < Copy/sport.txt | cut -d"," -f1,2 | ( if [ `cat lesson4_task4.txt` == "ano" ] then tr -s "[:upper:]" "[:lower:]" else tr -s "[:lower:]" "[:upper:]" fi )?
tail -n 5 Copy/sport.txt | cut -d"," -f1,2 | ( [ $(cat lesson4_task4.txt) == "ano" ] && tr -s "[:upper:]" "[:lower:]" || tr -s "[:lower:]" "[:upper:]" ) >/dev/stdoutV noci jsem byl už zblblej pipu jsem nadužival viz cat Copy/sport.txt, přitom tail umí číst normálně ze souboru. Mám i vyřešený výstup do souboru, /dev/stdout je tam teď jen pro účely ladění. Ale musím uznat, že tvoje verze s if - else je čitelnější. Děkuji za pomoc. A já si budu muset nastudovat rozdíl mezi () a $()
A já si budu muset nastudovat rozdíl mezi () a $()
(list) list is executed in a subshell environment (...). Variable assignments and builtin commands that affect the shell's environment do not remain in effect after the command completes. The return status is the exit status of list.
Command substitution allows the output of a command to replace the command name. There are two forms:
$(command)
or
`command`
Bash performs the expansion by executing command in a subshell environment and replacing the command substitution with the standard output of the
command
tail -n 5 Copy/sport.txt | cut -d"," -f1,2 | ( [ $(cat lesson4_task4.txt) == "ano" ] && tr -s "[:upper:]" "[:lower:]" || ( [ $(cat lesson4_task4.txt) == "ne" ] && tr -s "[:lower:]" "[:upper:]" || echo "CHYBA" ) ) >/dev/stdoutnebo čitelněji s if dle rastose:
tail -n 5 Copy/sport.txt | cut -d"," -f1,2 | ( if [ $(cat lesson4_task4.txt) == "ano" ] ; then tr -s "[:upper:]" "[:lower:]" else if [ $(cat lesson4_task4.txt) == "ne" ] ; then tr -s "[:lower:]" "[:upper:]" else echo "CHYBA" fi fi ) >/dev/stdout
sport="$(tail -n5 Copy/sport.txt | cut -d"," -f1,2)" lesson="$(<lesson4_task4.txt)" [[ $lesson == ano ]] && echo "${sport,,}" || ([[ $lesson == ne ]] && echo "${sport^^}" || echo "CHYBA")
A Bash 3 má kdo? Národní technické muzeum?
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.