Hi Viresh,

On 5/22/2025 3:15 PM, Viresh Kumar wrote:
On 22-05-25, 14:07, Sapkal, Swapnil wrote:
Initially I tried the same, but it does not work properly with the root user.

Hmm,

Tried chatgpt now and it says this should work:

if ! cat "$1/$file" 2>/dev/null; then
     printf "$file is not readable\n"
fi

- This attempts to read the file.
- If it fails, the cat command returns non-zero, and you print a message.
- 2>/dev/null suppresses error messages (Permission denied, etc.)
- This works reliably for both root and non-root users, because it actually 
tests the read action, not just permission bits.


This looks clean. I will send v2 with this change.

--
Thanks and Regards,
Swapnil

Reply via email to