Portál AbcLinuxu, 10. května 2025 08:08
Řešení dotazu:
IFS=''; OUTPUT=`./program`
Ovšem pokud je výstup dlouhý, asi by bylo lepší přesměrovat jej do souboru a pracovat pak se souborem.
./program > soubor.txt
...
rm soubor.txt
OUT=`./program` if ["$?" eq 0] then $OUTPUT >> log.log else ./program2 -p1 yyy -p2 xxx p3 $OUTPUT fi
#!/bin/bash OUT=`./program` if [ $? -eq 0 ]; then echo "$OUT" >> log.log else ./program2 "$OUTPUT" fi
$OUT
s a bez uvodzoviek.
host:~$ OUT=`echo; echo; echo; echo; echo "text"; echo; echo; echo`; echo $OUT text host:~$ OUT=`echo; echo; echo; echo; echo "text"; echo; echo; echo`; echo "$OUT" text host:~$
Command Substitution
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 and replacing the command substitution
with the standard output of the command, with any trailing newlines deleted. Embedded
newlines are not deleted, but they may be removed during word splitting. The command sub‐
stitution $(cat file) can be replaced by the equivalent but faster $(< file).
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.