bash - change directory inside a script wont work

丶灬走出姿态 提交于 2019-12-12 05:11:54

问题



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


回答1:


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.



来源:https://stackoverflow.com/questions/16752776/bash-change-directory-inside-a-script-wont-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!