I am attempting to write a script that will generate a random number and then make a directory called that random number and copy in a text file. I have tried everything i could think of the assign the variable but each time i get
RANDOM: command not found
RANDOM: command not found
bash: //small.txt: No such file or directory
bash: //small.txt: No such file or directory
Below is my code
#!/bin/bash
one=$(RANDOM)
two=$(RANDOM)
mkdir -p $one
mkdir -p $two
echo “BIGGGGGONgrery54y457457yytewrterytyutytytyhtytryrtyrthrthtrhrtyhrthrhtrhrthrthrthrthE”| > $one/small.txt
echo “B”| > $two/small.txt
echo "finish -l test me "
done
It’s not illegal syntax (it does mean something), it’s just the wrong syntax for what you want. Instead of
$(RANDOM)you want${RANDOM}or even just$RANDOM.When you use
$()it’s a command substitution, so bash is literally trying to execute a command namedRANDOM, which is why you get command not found and nothing in your variables.Your I/O redirection also looks wrong… to write to a file you should use:
Note that I removed the
|.