Hello everyone and thanks in advance.
I have never seen this behaviour before. Does anyone know why Bash isn’t processing the asterisk as a wildcard? It is a rather fresh Manjaro install.
Hello everyone and thanks in advance.
I have never seen this behaviour before. Does anyone know why Bash isn’t processing the asterisk as a wildcard? It is a rather fresh Manjaro install.
could the problem be that you are not even using bash, but zsh?
I thought so, but I checked echo $SHELL and it returned /bin/bash
Yakuake says it is zsh, though.
Does the asterisk wildcard not work with zsh? I have tried escaping it with \ and ’ ', but to no avail.
try seeing if this helps you figure out your issue https://unix.stackexchange.com/questions/589508/how-to-get-asterisk-in-zsh-to-have-same-behaviour-as-bash
This is right. zsh behaves a little differently with wildcard. You can add quotes to the directory (example sudo rm ‘/var/lib/mysql/*’) , or change default $SHELL to /bin/bash
Yes it warns if the expanded list is empty. It may depend on how it’s configured, but I assure you globbing does work with zsh
.
% ls testy/*
testy/dir1:
file
testy/dir2:
file
If you escape a special character then it’ll lose the special meaning. Check your config for options that affect globbing.
EDIT:
% ls 'testy/*'
ls: cannot access 'testy/*': No such file or directory
It doesn’t work with double quotes either.
The reason it doesn’t work is because you have no access rights to the files in the directory as your normal account, which is needed for the asterisk to compose the list.
PS: You output in the image clearly shows you are using ZSH and not bash, because the error returned is from ZSH
I have tried escaping it with \ and wrapping it with " " and ’ '. I have also tried adding the glob qualifier (N) at the end and also adding
unsetopt nomatch
at the end of my .zshrc, but nothing has worked for me thus far.
Right, I logged in as su and that changed the shell to bash and then it worked, but not because it worked on zsh.
I know you said, my point was that you shouldn’t try because the globbing is a special meaning and escaping it will make it a normal asterisk.
Of course, nice catch.
Changing to the root user will make it work in any shell because the root user does have access to those files…
I guess, so but su is set to use bash by default. Anyways, this takes power away from sudo, which is meant to give you those powers. I see it as an inconvenience, since everything else works with sudo.
Try this:
sudo chmod a+rx /var/lib/mysql
After that you should be able to do a normal ls on the mysql dir as normal user…
You are confusing power of sudo and your knowledge about directory permissions…
Nothing is taking away powers of sudo, it’s just you who doesn’t know how permissions work
Also, yes, but as a normal user, I think it is best practice not to have access to anything but the home directory unless using sudo or an equivalent.
Having access to something as a normal user is completely unrelated to being able to run other commands using sudo…
Your command:
sudo rm /var/lib/mysql/*
Does not work because your shell, (which is operating under your normal user), is unable to replace the asterisk with all the files in that directory.
Hence the correct error returned from your shell (ZSH)
You could change that command to this to make it work, because this time the command which is run as root will compose the list it self:
sudo find /var/lib/mysql -mindepth 1 -delete
First run that command without the -delete
argument, to show what it finds.
If you want to use sudo
and globbing without changing permissions, either of these will work.
sudo bash -c "ls /etc/sudoers.d/*"
sudo zsh -c "ls /etc/sudoers.d/*"
I’ve used another directory that would produce this error as I don’t have the mysql dir and I won’t be the only one. I’ve used ls
so it’s safe to try it out, obviously just replace with rm
and the proper path.
@Centaro
Next time please dont post screenshots, but use codeblocks to paste command output, see:
I’m changing the topic title to reflect the actual problem…
I am no pro, but I don’t appreciate the snarky remarks @TriMoon.
Anyways, I appreciate you all taking your time to support me and pointing me in the right direction,