t28292
t28292

Reputation: 573

where is the error in the following code in solaris bash?

I have wrote in my script

#!/usr/bin/bash
date=`dat '+%y%m%d_%H%M%S'`
Output=/Tamara/output_$date
echo $Output
`mkdir $Output`

But then when I run the script, i get the following:

/Tamara/output_23223_242222
mkdir: Failed to make directory "/Tamara/output_23223_342222'; No such file or directory

Why is this error displayed ?

Upvotes: 0

Views: 108

Answers (1)

jlliagre
jlliagre

Reputation: 30813

line 1:

#!/usr/bin/bash

for a better portability, should be:

#!/bin/bash

line 2:

date=`dat '+%y%m%d_%H%M%S'`

A typo here, should be:

date=`date '+%y%m%d_%H%M%S'`

or better:

date=$(date '+%y%m%d_%H%M%S')

or even better, to avoid the Y2.1K bug:

date=$(date '+%Y%m%d_%H%M%S')

lines 3:

Output=/Tamara/output_$date

/Tamara is dubious, ~/Tamara would be better (or perhaps ~Tamara).

line 4:

echo $Output

No problem with the code of this line but if it really displays /Tamara/output_23223_242222, that is both a bogus date and time. I would expect something like /Tamara/output_130817_215135

line 5:

`mkdir $Output`

Two issues here, backticks serve no purpose and an option is missing:

mkdir -p $Output

Upvotes: 2

Related Questions