Comments on: Understanding & Learning Basic Shell Scripting and Linux Filesystem Troubleshooting – Part 10 https://www.tecmint.com/linux-basic-shell-scripting-and-linux-filesystem-troubleshooting/ Tecmint - Linux Howtos, Tutorials, Guides, News, Tips and Tricks. Wed, 19 Sep 2018 05:47:03 +0000 hourly 1 By: Gabriel A. Cánepa https://www.tecmint.com/linux-basic-shell-scripting-and-linux-filesystem-troubleshooting/comment-page-1/#comment-784279 Thu, 26 May 2016 12:27:40 +0000 http://www.tecmint.com/?p=9694#comment-784279 In reply to BV Naagabaabu.

I’m glad to hear that you were able to solve your issue. And thanks for sharing your solution with us!

]]>
By: BV Naagabaabu https://www.tecmint.com/linux-basic-shell-scripting-and-linux-filesystem-troubleshooting/comment-page-1/#comment-784059 Wed, 25 May 2016 15:36:57 +0000 http://www.tecmint.com/?p=9694#comment-784059 In reply to Gabriel Cánepa.

hi Gabriel.,
thanks for the suggestion. after some search I came to know that we can’t use wild cards in if conditions to check similar files existence.
I got an alternate solution using ls command. below is how it works

ls -l /home/user/file_*
res=$?

if [ $res =0 ]
then
echo “all files exists”
else
echo “all files not exists”
fi

]]>
By: Gabriel A. Cánepa https://www.tecmint.com/linux-basic-shell-scripting-and-linux-filesystem-troubleshooting/comment-page-1/#comment-783660 Mon, 23 May 2016 16:58:12 +0000 http://www.tecmint.com/?p=9694#comment-783660 In reply to BV Naagabaabu.

Please check the accepted answer in this Stackoverflow post: http://stackoverflow.com/questions/19354024/using-wildcards-in-bash-if-statement and let me know if it solves your issue.

]]>
By: BV Naagabaabu https://www.tecmint.com/linux-basic-shell-scripting-and-linux-filesystem-troubleshooting/comment-page-1/#comment-783647 Mon, 23 May 2016 16:06:34 +0000 http://www.tecmint.com/?p=9694#comment-783647 In reply to BV Naagabaabu.

Hi Gabriel.,

Tested this and came to know that the problem is not with if condition, it is with wild cards., Below is my scenario

i have 3 files and one directory. Those 3 files are named as file_name1, file_name2, file_name3 and the directory name is logs.

for checking those 3 files and directory existence, i write a if condition like below.

if [[ -f /home/user/file_* && -d /home/user/logs ]]

while executing the above, IF condition is break at first condition, because it doesn’t find the file “/home/user/file_*”.

How can i use a wild card in if condition

]]>
By: BV Naagabaabu https://www.tecmint.com/linux-basic-shell-scripting-and-linux-filesystem-troubleshooting/comment-page-1/#comment-783634 Mon, 23 May 2016 14:41:20 +0000 http://www.tecmint.com/?p=9694#comment-783634 In reply to Gabriel Cánepa.

hi Gabriel,
Thanks for the quick reply. coming to my scenario.,

i,’m using BASH shell. In a shell script I need to check the file and directory exists or not. if both are available then they should be deleted.

while using the above if condition(I mentioned) my script was stopped after checking first condition(here file existence) in if condion. while debugging (with set -x) i got to know that it was not checking the directory existence.

I will apply your fix and post my output.

]]>