bash - Passing pipe output to Test command -


i'm confused test command syntax. goal check if file exists, file path formed sed command.

so, try, example:

echo '~/test111' | sed s/111/222/g | test -f && echo "found" || echo "not found" 

but command returns "found". doing wrong?

with currenty approach, saying:

test -f && echo "yes" || echo "no" 

since test -f returns true default, getting "yes":

$ test -f $ echo $? 0 

the correct syntax test -f "string":

so want say:

string=$(echo '~/test111'|sed 's/111/222/g') test -f "$string" && echo "found" || echo "not found" 

which can compacted into:

test -f "$(echo '~/test111'|sed 's/111/222/g')" && echo "found" || echo "not found" 

but looses readability.

and can use xargs perform given action in name given previous pipe:

echo '~/test111'|sed 's/111/222/g' | xargs test -f && echo "found" || echo "not found" 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

excel vba - VBA Proxy auto-configuration for http requests -

php - phpWord - Tables with borders in headers/footers -