Stipe Viskov
Stipe Viskov

Reputation: 23

bin bash bad interpreter

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

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

Upvotes: 1

Views: 6520

Answers (4)

glenn jackman
glenn jackman

Reputation: 247042

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

Upvotes: 2

Beggarman
Beggarman

Reputation: 896

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.

Your script, updated:

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

Upvotes: 0

clt60
clt60

Reputation: 63962

Or with an simple

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

if you want zad1, zad2 .. zad5

or

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

if you want zad, zad1, zad2 .. zad5

Upvotes: 1

Eugene
Eugene

Reputation: 7258

It should be

#!/bin/bash

(first slash)

Upvotes: 5

Related Questions