bin bash 糟糕的解释器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25451243/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 11:12:55  来源:igfitidea点击:

bin bash bad interpreter

bashunixterminalbin

提问by Stipe Viskov

#! bin/bash
mkdir ~/folder
while [ $brojac -le 5]
do
mkdir ~/folder/zad"$brojac"
brojac = $(( brojac+1 ))
done

this is my shellscript,but when I want to run it in terminal, I receive this error

这是我的 shellscript,但是当我想在终端中运行它时,我收到此错误

mint@mint ~ $ ./prvi.sh
bash: ./prvi.sh: bin/bash: bad interpreter: No such file or directory
mint@mint ~ $ 

采纳答案by Beggarman

Small errors in your script:

脚本中的小错误:

  1. $brojac is unassigned, so your integer comparison fails. Assign it an initial value to fix.
  2. '[' calls test, so you need spaces around opening and closing braces.
  3. You can't have spaces around your equal sign when assigning a value.
  1. $brojac 未分配,因此您的整数比较失败。为其分配一个初始值以进行修复。
  2. '[' 调用 test,因此您需要在左括号和右括号周围留出空格。
  3. 分配值时,等号周围不能有空格。

Your script, updated:

您的脚本已更新:

#!/bin/bash
mkdir ~/folder
brojac=0
while [ $brojac -le 5 ]
do
    mkdir ~/folder/zad"$brojac"
    brojac=$(( brojac+1 ))
done

回答by Eugene

It should be

它应该是

#!/bin/bash

(first slash)

(第一个斜线)

回答by glenn Hymanman

#!/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

I would write:

我会写:

for ((i=0; i<=5, i++)); do
    mkdir -p ~/folder/zad$i
done

回答by jm666

Or with an simple

或者用一个简单的

mkdir -p ~/folder/zad{1..5}

if you want zad1, zad2 .. zad5

如果你想 zad1, zad2 .. zad5

or

或者

mkdir -p ~/folder/zad{,1..5}

if you want zad, zad1, zad2 .. zad5

如果你想 zad, zad1, zad2 .. zad5