Search code examples
shellzshubuntu-18.04rosoh-my-zsh

ZSH doesn't identify "*" as "all files"


I use ZSH shell environment (with 'oh-my-zsh' plugin) on my Ubuntu 18.04 and I have noticed an issue with it. I think my ZSH shell doesn't identify * sometimes as "all files".

For example if I wanted to install all ROS packages with the prefix control I would enter the command : sudo apt-get install ros-melodic-control* and this should work and install all ROS Melodic packages starting with control from the main ROS repository. This thing worked when I used BASH earlier. But now when I do the same thing in ZSH it gives me the following error : zsh: no matches found: ros-melodic-control*

It would be great if someone helped me identify the exact problem.

TIA


Solution

  • It's the difference between zsh and bash. zsh never will run a command that contains wildcard pattern that doesn't match existing files. Bash will execute as is.

    It also may fail differently. If look-up would return anything that matches the pattern, , eg. a file named ros-melodic-control.pdf, zsh will execute sudo apt-get install ros-melodic-control.pdf. NB: wildcards always are investigated by the shell.

    Consider it be a paranoid shell for non-root users who primarily interact only with file system. To actually do what you want you have to use single quotes.

     sudo apt-get install 'ros-melodic-control*'
    

    Packages given as argument to apt-get aren't files. they are names in database which also contains their location (local cache in /var, disk, remote server or NFS source). SO you have to ensure they are passed as string if you use wildcards. Just with bash\sh\ksh you can get away without quotes if you have no matching files.

    Adding quotes would pass enclosed text "as-is" to arguments of executed program, as a string. Therefore apt-get will receive string ros-melodic-control* and will search for packages that matches it. Without quotes shell will try to expand wildcards.