#! bin/bash
mkdir ~/folder
while [ $brojac -le 5]
do
mkdir ~/folder/zad"$brojac"
brojac = $(( brojac+1 ))
done
这是我的shellcript,但是当我想在终端中运行它时,我收到此错误
mint@mint ~ $ ./prvi.sh
bash: ./prvi.sh: bin/bash: bad interpreter: No such file or directory
mint@mint ~ $
答案 0 :(得分:5)
应该是
#!/bin/bash
(第一次斜线)
答案 1 :(得分:2)
#!/bin/bash
mkdir ~/folder
brojac=0
while [ "$brojac" -le 5 ] # with [...], need to quote vars and spaces around [ and ]
do
mkdir ~/folder/zad"$brojac"
brojac=$(( brojac+1 )) # cannot have spaces around =
done
我会写:
for ((i=0; i<=5, i++)); do
mkdir -p ~/folder/zad$i
done
答案 2 :(得分:1)
或者用简单的
mkdir -p ~/folder/zad{1..5}
如果您需要zad1, zad2 .. zad5
或
mkdir -p ~/folder/zad{,1..5}
如果您需要zad, zad1, zad2 .. zad5
答案 3 :(得分:0)
脚本中的小错误:
您的脚本已更新:
#!/bin/bash
mkdir ~/folder
brojac=0
while [ $brojac -le 5 ]
do
mkdir ~/folder/zad"$brojac"
brojac=$(( brojac+1 ))
done