vendredi 13 novembre 2020

Bash and Operator does not work, even with right syntax

I want to only do some code if $# equals 1 and $1 is a readable existing file. I have following code:

if [[ $# -eq 1 ] -a [ test -r $1 ]]

I have tried many different solutions for an and statement. Like

[ $# -eq 1 ] $$ [ test -r $1 ]
[ $# -eq 1 -a test -r $1 ]

and many more...

Nothing seems to work. I think its because of the test command. Sometimes I get an error like test not found or too many arguments or smth else

My whole code:

#!/bin/bash
if [[ $# -eq 1 ] -a [ test -r $1 ]]
then
groupadd -f "TAI12A"
IFS=:
while read nachname vorname klasse
do
nutzername=$nachname$vorname
groupadd -f $klasse
useradd -g "TAI12A" -G $klasse -s /bin/bash -m -p "taipasswd $nutzername
done < $1
else
echo "Uebergabewerte fehlerhaft"
fi

Aucun commentaire:

Enregistrer un commentaire