That's all. They just won't work for me. What did I do wrong this time?

    # nquo is: /home/bryan/renametest/C D/y z

    # script:
    dirn=dirname "$nquo"
    echo "dirn $dirn"
    bnam=basename "$nquo"
    echo "bnam $bnam"

Run result:

    ./script3.sh: 208: /home/bryan/renametest/C D/y z: Permission denied
    dirn 
    ./script3.sh: 208: /home/bryan/renametest/C D/y z: Permission denied
    bnam 
有帮助吗?

解决方案

As it stands, your script is trying to run the file named in $nquo first with the environment variable dirn set to the value dirname, and then with the variable bnam set to the value basename. Since it is not executable, you get the error message about not being able to execute the file.

You presumably intended to run the commands on the name of the file, which requires either back-ticks or (preferably) $(...) around it:

dnam=$(dirname "$nquo")
bnam=$(basename "$nquo")
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top