Git-bash 字符串变量返回为 null
Git-bash string variable is returned as null
问题与 和 100 多个类似的其他 SO 线程有关。我有一个像下面这样的变量及其用法:
branchtochechout = "develop"
echo "Branch To Chechout is : $branchtochechout"
for thedir in ./*/ ;
do (
echo -e "Checking out in the directory:$thedir";
cd "$thedir" && git checkout $branchtochechout);
sleep 2
done
令我惊讶的是,$branchtochechout 在 echo 语句以及 for 循环中都为我提供了 null。 git-bash (windows) 的工作方式与 linux bash 脚本不同吗?请帮助我了解我在这里做错了什么?
您不能在变量赋值中将空格放在 =
周围。
另外,引用您的变量,并添加一个 shebang。
尝试 https://www.shellcheck.net/
Line 1:
branchtochechout = "develop"
^-- SC2148 (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.
^-- SC2283 (error): Remove spaces around = to assign (or use [ ] to compare, or quote '=' if literal).
Line 3:
echo "Branch To Chechout is : $branchtochechout"
^-- SC2154 (warning): branchtochechout is referenced but not assigned.
Line 8:
cd "$thedir" && git checkout $branchtochechout);
^-- SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean: (apply this, apply all SC2086)
cd "$thedir" && git checkout "$branchtochechout");
问题与
branchtochechout = "develop"
echo "Branch To Chechout is : $branchtochechout"
for thedir in ./*/ ;
do (
echo -e "Checking out in the directory:$thedir";
cd "$thedir" && git checkout $branchtochechout);
sleep 2
done
令我惊讶的是,$branchtochechout 在 echo 语句以及 for 循环中都为我提供了 null。 git-bash (windows) 的工作方式与 linux bash 脚本不同吗?请帮助我了解我在这里做错了什么?
您不能在变量赋值中将空格放在 =
周围。
另外,引用您的变量,并添加一个 shebang。
尝试 https://www.shellcheck.net/
Line 1:
branchtochechout = "develop"
^-- SC2148 (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.
^-- SC2283 (error): Remove spaces around = to assign (or use [ ] to compare, or quote '=' if literal).
Line 3:
echo "Branch To Chechout is : $branchtochechout"
^-- SC2154 (warning): branchtochechout is referenced but not assigned.
Line 8:
cd "$thedir" && git checkout $branchtochechout);
^-- SC2086 (info): Double quote to prevent globbing and word splitting.
Did you mean: (apply this, apply all SC2086)
cd "$thedir" && git checkout "$branchtochechout");