jeudi 25 décembre 2014

checking whether a command is executed or not within if in bash

I am new in bash programming , was try to execute a program which will create a directory on basis of complete path provided to it from prompt and if directory already exists it will return error for directory already exists and ask again for name in recursive function. here it is what I did


let say a file test1 in it



#!/bin/bash
echo "enter the directory name"
read ab
check(){
if (( echo `mkdir $ab` 2>/dev/null )); then
echo "directory created "
echo `ls -ld $ab`
exit
else
echo "try again "
echo "enter new value for directory:
read ab
check
fi
}
check


the problem here is if the directory exists then the program works fine but if does not exist then it creates it but then goes to the else part of the program . please help


Aucun commentaire:

Enregistrer un commentaire