# [[ -f "/boot/vmlinuz*" ]] && echo "ok"
# ls /boot/vmlinuz-2.6.32-279.el6.x86_64
/boot/vmlinuz-2.6.32-279.el6.x86_64
it doesn't return ok , any one help?
# [[ -f "/boot/vmlinuz*" ]] && echo "ok"
# ls /boot/vmlinuz-2.6.32-279.el6.x86_64
/boot/vmlinuz-2.6.32-279.el6.x86_64
it doesn't return ok , any one help?
In the [[...]]
construct, the word following -f
has to be a file-name path and not a pattern for a file-name path. -f
will treat your provided pattern as a literal file-name and the other statement will not get executed.
An alternative to get what you want could be:
a=$(print /boot/vmlinuz*)
[[ $a != "/boot/vmlinuz*" && -f $a ]] && echo OK
I am assuming only one file in the directory with that pattern or none.
If multiple files or directories with that pattern may exist and if you are not averse to using a simple loop, you may try:
ls -d /boot/vmlinuz*|while read
do
[[ -f $REPLY ]] && echo "$REPLY" is OK
done
Hi elixir_sinari,
I think your first/previous code is correct...
a=/boot/vmlinuz*
echo $a
/boot/vmlinuz-2.6.32-279.el6.x86_64
[[ $a == /boot/vmlinuz* ]] && echo OK
OK
Check now. I'd made a mistake. When a variable assignment such as a=/boot/vmlinuz*
is made, the value stored in a
will be /boot/vmlinuz*
and nothing else. When that variable is evaluated, the expansion of *
is done depending on whether you quote it or not.
it still not ok
# kernel="/boot/vmlinuz*"
# echo $kernel
/boot/vmlinuz-2.6.32-279.el6.x86_64
[[ -f $kernel ]] && echo "ok"
#
Check my first post in this thread.