bash - change directory inside a script wont work

2019-08-28 20:28发布


Try to find a solution for a problem but stucked with the following :

I have a path of a folder (I got full path and partial path).
Im tying to cd to that folder, but it keep saying "No such file or directory". Thats the partial code :

for var in "$@" ; do
    if [[ -d $var ]] ; then
        if [ "$(ls -A $var)" ]; then
            cd $var

Would appericiate any help :) Thanks

标签: bash cd
1条回答
一纸荒年 Trace。
2楼-- · 2019-08-28 20:53

I think this line is your problem:

    if [ "$(ls -A $var)" ]; then

Why do you need this test at all? Your previous check looks for the existence of the directory already.

查看更多
登录 后发表回答