With the currenty approach, you are just saying:
test -f && echo "yes" || echo "no"
Since test -f
returns true as default, you are always getting "yes":
$ test -f
$ echo $?
0
The correct syntax is test -f "string"
:
So you want to say:
string=$(echo '~/test111'|sed 's/111/222/g')
test -f "$string" && echo "found" || echo "not found"
Which can be compacted into:
test -f "$(echo '~/test111'|sed 's/111/222/g')" && echo "found" || echo "not found"
but it loses readability.
And also you can use xargs
to perform the given action in the name given by the previous pipe:
echo '~/test111'|sed 's/111/222/g' | xargs test -f && echo "found" || echo "not found"