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.