How to create a directory by combining two name?











up vote
2
down vote

favorite
1












I am on Redhat.



I am trying create directory by combining three names.



I have a property file, this is what it looks like:



build_name = MyBuild
build_no = 100
appServer_version = jboss6.1`


I read this property file and I am trying to create a directory by combining all three names. After creating directory it should look like that.



MYBuild-100-jboss6.1


Here what I have tried



file="./app.properties"

if [ -f "$file" ]
then
echo "$file found."

while IFS='=' read -r key value
do
key=$(echo $key | tr '.' '_')
eval "${key}='${value}'"
done < "$file"

echo "build_name = " ${build_name}
echo "build_no = " ${build_no}
echo "Jboss_version = "${jboss_version}
echo "Got the value from property file"


name=${build_name}-
build=${build_no}-
Jboss=${jboss_version}

fileName="${name}${build}${Jboss}"

mkdir $fileName

else
echo "$file not found."
fi


When I run this , It always create three different directory,
with name MyBuild , 100 , jboss6.1. Where am doing wrong.



update 1



file="./app.properties"

ARRAY=()
if [ -f "$file" ]
then
echo "$file found."

IFS='='
while read -r key value
do
val=$(echo "$value" | tr -d '[[:space:]]')
ARRAY+=("$val")
done < "$file"

IFS='-'
newdir="${ARRAY[*]}"
echo "mkdir $newdir"

if[ -f "$newdir" ]
then
echo "$newdir allready exist."
rm -rf $newdir
mkdir "$newdir"
else
mkdir "$newdir"
else
echo "$file not found."
fi









share|improve this question
























  • You have extra spaces that read fetches. After from tr '.' '_' do also tr -s ' ' | tr -d ' ' for the key. And also perform such a tr for the value.
    – grochmal
    Aug 13 '16 at 19:42










  • still it does the same thing, can you please help me with that
    – Varun
    Aug 13 '16 at 19:54















up vote
2
down vote

favorite
1












I am on Redhat.



I am trying create directory by combining three names.



I have a property file, this is what it looks like:



build_name = MyBuild
build_no = 100
appServer_version = jboss6.1`


I read this property file and I am trying to create a directory by combining all three names. After creating directory it should look like that.



MYBuild-100-jboss6.1


Here what I have tried



file="./app.properties"

if [ -f "$file" ]
then
echo "$file found."

while IFS='=' read -r key value
do
key=$(echo $key | tr '.' '_')
eval "${key}='${value}'"
done < "$file"

echo "build_name = " ${build_name}
echo "build_no = " ${build_no}
echo "Jboss_version = "${jboss_version}
echo "Got the value from property file"


name=${build_name}-
build=${build_no}-
Jboss=${jboss_version}

fileName="${name}${build}${Jboss}"

mkdir $fileName

else
echo "$file not found."
fi


When I run this , It always create three different directory,
with name MyBuild , 100 , jboss6.1. Where am doing wrong.



update 1



file="./app.properties"

ARRAY=()
if [ -f "$file" ]
then
echo "$file found."

IFS='='
while read -r key value
do
val=$(echo "$value" | tr -d '[[:space:]]')
ARRAY+=("$val")
done < "$file"

IFS='-'
newdir="${ARRAY[*]}"
echo "mkdir $newdir"

if[ -f "$newdir" ]
then
echo "$newdir allready exist."
rm -rf $newdir
mkdir "$newdir"
else
mkdir "$newdir"
else
echo "$file not found."
fi









share|improve this question
























  • You have extra spaces that read fetches. After from tr '.' '_' do also tr -s ' ' | tr -d ' ' for the key. And also perform such a tr for the value.
    – grochmal
    Aug 13 '16 at 19:42










  • still it does the same thing, can you please help me with that
    – Varun
    Aug 13 '16 at 19:54













up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






1





I am on Redhat.



I am trying create directory by combining three names.



I have a property file, this is what it looks like:



build_name = MyBuild
build_no = 100
appServer_version = jboss6.1`


I read this property file and I am trying to create a directory by combining all three names. After creating directory it should look like that.



MYBuild-100-jboss6.1


Here what I have tried



file="./app.properties"

if [ -f "$file" ]
then
echo "$file found."

while IFS='=' read -r key value
do
key=$(echo $key | tr '.' '_')
eval "${key}='${value}'"
done < "$file"

echo "build_name = " ${build_name}
echo "build_no = " ${build_no}
echo "Jboss_version = "${jboss_version}
echo "Got the value from property file"


name=${build_name}-
build=${build_no}-
Jboss=${jboss_version}

fileName="${name}${build}${Jboss}"

mkdir $fileName

else
echo "$file not found."
fi


When I run this , It always create three different directory,
with name MyBuild , 100 , jboss6.1. Where am doing wrong.



update 1



file="./app.properties"

ARRAY=()
if [ -f "$file" ]
then
echo "$file found."

IFS='='
while read -r key value
do
val=$(echo "$value" | tr -d '[[:space:]]')
ARRAY+=("$val")
done < "$file"

IFS='-'
newdir="${ARRAY[*]}"
echo "mkdir $newdir"

if[ -f "$newdir" ]
then
echo "$newdir allready exist."
rm -rf $newdir
mkdir "$newdir"
else
mkdir "$newdir"
else
echo "$file not found."
fi









share|improve this question















I am on Redhat.



I am trying create directory by combining three names.



I have a property file, this is what it looks like:



build_name = MyBuild
build_no = 100
appServer_version = jboss6.1`


I read this property file and I am trying to create a directory by combining all three names. After creating directory it should look like that.



MYBuild-100-jboss6.1


Here what I have tried



file="./app.properties"

if [ -f "$file" ]
then
echo "$file found."

while IFS='=' read -r key value
do
key=$(echo $key | tr '.' '_')
eval "${key}='${value}'"
done < "$file"

echo "build_name = " ${build_name}
echo "build_no = " ${build_no}
echo "Jboss_version = "${jboss_version}
echo "Got the value from property file"


name=${build_name}-
build=${build_no}-
Jboss=${jboss_version}

fileName="${name}${build}${Jboss}"

mkdir $fileName

else
echo "$file not found."
fi


When I run this , It always create three different directory,
with name MyBuild , 100 , jboss6.1. Where am doing wrong.



update 1



file="./app.properties"

ARRAY=()
if [ -f "$file" ]
then
echo "$file found."

IFS='='
while read -r key value
do
val=$(echo "$value" | tr -d '[[:space:]]')
ARRAY+=("$val")
done < "$file"

IFS='-'
newdir="${ARRAY[*]}"
echo "mkdir $newdir"

if[ -f "$newdir" ]
then
echo "$newdir allready exist."
rm -rf $newdir
mkdir "$newdir"
else
mkdir "$newdir"
else
echo "$file not found."
fi






shell-script






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 at 22:50









Rui F Ribeiro

38.3k1477127




38.3k1477127










asked Aug 13 '16 at 19:38









Varun

1134




1134












  • You have extra spaces that read fetches. After from tr '.' '_' do also tr -s ' ' | tr -d ' ' for the key. And also perform such a tr for the value.
    – grochmal
    Aug 13 '16 at 19:42










  • still it does the same thing, can you please help me with that
    – Varun
    Aug 13 '16 at 19:54


















  • You have extra spaces that read fetches. After from tr '.' '_' do also tr -s ' ' | tr -d ' ' for the key. And also perform such a tr for the value.
    – grochmal
    Aug 13 '16 at 19:42










  • still it does the same thing, can you please help me with that
    – Varun
    Aug 13 '16 at 19:54
















You have extra spaces that read fetches. After from tr '.' '_' do also tr -s ' ' | tr -d ' ' for the key. And also perform such a tr for the value.
– grochmal
Aug 13 '16 at 19:42




You have extra spaces that read fetches. After from tr '.' '_' do also tr -s ' ' | tr -d ' ' for the key. And also perform such a tr for the value.
– grochmal
Aug 13 '16 at 19:42












still it does the same thing, can you please help me with that
– Varun
Aug 13 '16 at 19:54




still it does the same thing, can you please help me with that
– Varun
Aug 13 '16 at 19:54










3 Answers
3






active

oldest

votes

















up vote
2
down vote



accepted










You have two issue there, first are spaces which are left in your variables when you perform the read with IFS='='. Second is that you actually do not have jboss_version in your app file. One way to do this would be:



file="./app.properties"

if [ -f "$file" ]
then
echo "$file found."

while IFS='=' read -r key value
do
key=$(echo $key | tr '.' '_' | tr -d ' ' | tr -d 't')
val=$(echo $value | tr -d ' ' | tr -d 't')
eval "${key}='${val}'"
done < "$file"

echo "build_name = " ${build_name}
echo "build_no = " ${build_no}
echo "Jboss_version = "${appServer_version}
echo "Got the value from property file"


name=${build_name}-
build=${build_no}-
Jboss=${appServer_version}

fileName="${name}${build}${Jboss}"

echo mkdir [$fileName]

else
echo "$file not found."
fi


Yet, I would do it in a different way. By forcing IFS to be used in the split and in the join as well, this also uses all variables from the app.properties file:



file="./app.properties"

ARRAY=()
if [ -f "$file" ]
then
echo "$file found."

IFS='='
while read -r key value
do
val=$(echo "$value" | tr -d '[[:space:]]')
ARRAY+=("$val")
done < "$file"

IFS='-'
newdir="${ARRAY[*]}"
if [ -d "$newdir" ]; then
echo "rm -rf $newdir"
rm -rf "$newdir"
fi
echo "mkdir $newdir"
mkdir "$newdir"
else
echo "$file not found."
fi





share|improve this answer























  • hey thanks thats worked, I would like one more help, If the newdir is already there i want to remove it and create a new one. for that I just added this , but its not working, I am really sorry for asking silly things, because I am totally new to this. please see the updated question
    – Varun
    Aug 13 '16 at 20:59












  • @varun - If the directory is empty you can simply do rmdir <dir> but you did not specify whether it is empty therefore I am assuming it is not. You need rm -rf in that case, I made an edit to the code in the answer. Note that rm -rf can be very destructive, I did an if in there for some security but be very careful with forward slashes (/) in names if you are using rm -rf.
    – grochmal
    Aug 13 '16 at 21:11










  • Thanks , It worked. I will keep in my what you suggested about rm -rf
    – Varun
    Aug 13 '16 at 21:15


















up vote
1
down vote













There are multiple problems with your script, without completely rewriting it you have to:




  • strip value from any spaces

  • use appServer_version in your script, like in the input file not JbossVersion


Working:



file="./app.properties"

if [ -f "$file" ]
then
echo "$file found."

while IFS='=' read -r key value
do
key=$(echo $key | tr '.' '_')
value=$(echo $value | sed 's/ //g')
eval "${key}='${value}'"
done < "$file"

echo "build_name = " ${build_name}
echo "build_no = " ${build_no}
echo "Jboss_version = "${appServer_version}
echo "Got the value from property file"


name=${build_name}-
build=${build_no}-
Jboss=${appServer_version}

fileName="${name}${build}${Jboss}"
echo $fileName
# mkdir $fileName

else
echo "$file not found."
fi





share|improve this answer





















  • I was here writing a better way to do it and you beat me by seconds :), A deserved +1
    – grochmal
    Aug 13 '16 at 20:26










  • @grochmal Sorry for that. I normally don't do much with pure bash, but came across this in the review queue. Your second solution is cleaner IMO.
    – Anthon
    Aug 13 '16 at 20:30










  • I actually meant it in a good way, reminds me to keep my guts. As Mark Pilgrim says: the one who makes the specification is not the one who makes the cleaner spec, but the one who delivers the first implementation.
    – grochmal
    Aug 13 '16 at 20:44


















up vote
0
down vote













to skip #comments or some rubbish in app.properties
#!/bin/bash



FILE="./app.properties"

SEP=
FILENAME=
while read -r LINE; do
LINE=$(echo ${LINE} | sed -rn -e '/=/{/#.*/d;s/[^=]+=([^=]+).*/1/;s/[ ]*//gp}' )
[[ -n ${LINE} ]] && FILENAME+=${SEP}${LINE} && [[ -z ${SEP} ]] && SEP="-"
done <"$FILE"

echo $FILENAME
#mkdir $FILENAME





share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f303243%2fhow-to-create-a-directory-by-combining-two-name%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    You have two issue there, first are spaces which are left in your variables when you perform the read with IFS='='. Second is that you actually do not have jboss_version in your app file. One way to do this would be:



    file="./app.properties"

    if [ -f "$file" ]
    then
    echo "$file found."

    while IFS='=' read -r key value
    do
    key=$(echo $key | tr '.' '_' | tr -d ' ' | tr -d 't')
    val=$(echo $value | tr -d ' ' | tr -d 't')
    eval "${key}='${val}'"
    done < "$file"

    echo "build_name = " ${build_name}
    echo "build_no = " ${build_no}
    echo "Jboss_version = "${appServer_version}
    echo "Got the value from property file"


    name=${build_name}-
    build=${build_no}-
    Jboss=${appServer_version}

    fileName="${name}${build}${Jboss}"

    echo mkdir [$fileName]

    else
    echo "$file not found."
    fi


    Yet, I would do it in a different way. By forcing IFS to be used in the split and in the join as well, this also uses all variables from the app.properties file:



    file="./app.properties"

    ARRAY=()
    if [ -f "$file" ]
    then
    echo "$file found."

    IFS='='
    while read -r key value
    do
    val=$(echo "$value" | tr -d '[[:space:]]')
    ARRAY+=("$val")
    done < "$file"

    IFS='-'
    newdir="${ARRAY[*]}"
    if [ -d "$newdir" ]; then
    echo "rm -rf $newdir"
    rm -rf "$newdir"
    fi
    echo "mkdir $newdir"
    mkdir "$newdir"
    else
    echo "$file not found."
    fi





    share|improve this answer























    • hey thanks thats worked, I would like one more help, If the newdir is already there i want to remove it and create a new one. for that I just added this , but its not working, I am really sorry for asking silly things, because I am totally new to this. please see the updated question
      – Varun
      Aug 13 '16 at 20:59












    • @varun - If the directory is empty you can simply do rmdir <dir> but you did not specify whether it is empty therefore I am assuming it is not. You need rm -rf in that case, I made an edit to the code in the answer. Note that rm -rf can be very destructive, I did an if in there for some security but be very careful with forward slashes (/) in names if you are using rm -rf.
      – grochmal
      Aug 13 '16 at 21:11










    • Thanks , It worked. I will keep in my what you suggested about rm -rf
      – Varun
      Aug 13 '16 at 21:15















    up vote
    2
    down vote



    accepted










    You have two issue there, first are spaces which are left in your variables when you perform the read with IFS='='. Second is that you actually do not have jboss_version in your app file. One way to do this would be:



    file="./app.properties"

    if [ -f "$file" ]
    then
    echo "$file found."

    while IFS='=' read -r key value
    do
    key=$(echo $key | tr '.' '_' | tr -d ' ' | tr -d 't')
    val=$(echo $value | tr -d ' ' | tr -d 't')
    eval "${key}='${val}'"
    done < "$file"

    echo "build_name = " ${build_name}
    echo "build_no = " ${build_no}
    echo "Jboss_version = "${appServer_version}
    echo "Got the value from property file"


    name=${build_name}-
    build=${build_no}-
    Jboss=${appServer_version}

    fileName="${name}${build}${Jboss}"

    echo mkdir [$fileName]

    else
    echo "$file not found."
    fi


    Yet, I would do it in a different way. By forcing IFS to be used in the split and in the join as well, this also uses all variables from the app.properties file:



    file="./app.properties"

    ARRAY=()
    if [ -f "$file" ]
    then
    echo "$file found."

    IFS='='
    while read -r key value
    do
    val=$(echo "$value" | tr -d '[[:space:]]')
    ARRAY+=("$val")
    done < "$file"

    IFS='-'
    newdir="${ARRAY[*]}"
    if [ -d "$newdir" ]; then
    echo "rm -rf $newdir"
    rm -rf "$newdir"
    fi
    echo "mkdir $newdir"
    mkdir "$newdir"
    else
    echo "$file not found."
    fi





    share|improve this answer























    • hey thanks thats worked, I would like one more help, If the newdir is already there i want to remove it and create a new one. for that I just added this , but its not working, I am really sorry for asking silly things, because I am totally new to this. please see the updated question
      – Varun
      Aug 13 '16 at 20:59












    • @varun - If the directory is empty you can simply do rmdir <dir> but you did not specify whether it is empty therefore I am assuming it is not. You need rm -rf in that case, I made an edit to the code in the answer. Note that rm -rf can be very destructive, I did an if in there for some security but be very careful with forward slashes (/) in names if you are using rm -rf.
      – grochmal
      Aug 13 '16 at 21:11










    • Thanks , It worked. I will keep in my what you suggested about rm -rf
      – Varun
      Aug 13 '16 at 21:15













    up vote
    2
    down vote



    accepted







    up vote
    2
    down vote



    accepted






    You have two issue there, first are spaces which are left in your variables when you perform the read with IFS='='. Second is that you actually do not have jboss_version in your app file. One way to do this would be:



    file="./app.properties"

    if [ -f "$file" ]
    then
    echo "$file found."

    while IFS='=' read -r key value
    do
    key=$(echo $key | tr '.' '_' | tr -d ' ' | tr -d 't')
    val=$(echo $value | tr -d ' ' | tr -d 't')
    eval "${key}='${val}'"
    done < "$file"

    echo "build_name = " ${build_name}
    echo "build_no = " ${build_no}
    echo "Jboss_version = "${appServer_version}
    echo "Got the value from property file"


    name=${build_name}-
    build=${build_no}-
    Jboss=${appServer_version}

    fileName="${name}${build}${Jboss}"

    echo mkdir [$fileName]

    else
    echo "$file not found."
    fi


    Yet, I would do it in a different way. By forcing IFS to be used in the split and in the join as well, this also uses all variables from the app.properties file:



    file="./app.properties"

    ARRAY=()
    if [ -f "$file" ]
    then
    echo "$file found."

    IFS='='
    while read -r key value
    do
    val=$(echo "$value" | tr -d '[[:space:]]')
    ARRAY+=("$val")
    done < "$file"

    IFS='-'
    newdir="${ARRAY[*]}"
    if [ -d "$newdir" ]; then
    echo "rm -rf $newdir"
    rm -rf "$newdir"
    fi
    echo "mkdir $newdir"
    mkdir "$newdir"
    else
    echo "$file not found."
    fi





    share|improve this answer














    You have two issue there, first are spaces which are left in your variables when you perform the read with IFS='='. Second is that you actually do not have jboss_version in your app file. One way to do this would be:



    file="./app.properties"

    if [ -f "$file" ]
    then
    echo "$file found."

    while IFS='=' read -r key value
    do
    key=$(echo $key | tr '.' '_' | tr -d ' ' | tr -d 't')
    val=$(echo $value | tr -d ' ' | tr -d 't')
    eval "${key}='${val}'"
    done < "$file"

    echo "build_name = " ${build_name}
    echo "build_no = " ${build_no}
    echo "Jboss_version = "${appServer_version}
    echo "Got the value from property file"


    name=${build_name}-
    build=${build_no}-
    Jboss=${appServer_version}

    fileName="${name}${build}${Jboss}"

    echo mkdir [$fileName]

    else
    echo "$file not found."
    fi


    Yet, I would do it in a different way. By forcing IFS to be used in the split and in the join as well, this also uses all variables from the app.properties file:



    file="./app.properties"

    ARRAY=()
    if [ -f "$file" ]
    then
    echo "$file found."

    IFS='='
    while read -r key value
    do
    val=$(echo "$value" | tr -d '[[:space:]]')
    ARRAY+=("$val")
    done < "$file"

    IFS='-'
    newdir="${ARRAY[*]}"
    if [ -d "$newdir" ]; then
    echo "rm -rf $newdir"
    rm -rf "$newdir"
    fi
    echo "mkdir $newdir"
    mkdir "$newdir"
    else
    echo "$file not found."
    fi






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Aug 13 '16 at 21:08

























    answered Aug 13 '16 at 20:25









    grochmal

    5,60131544




    5,60131544












    • hey thanks thats worked, I would like one more help, If the newdir is already there i want to remove it and create a new one. for that I just added this , but its not working, I am really sorry for asking silly things, because I am totally new to this. please see the updated question
      – Varun
      Aug 13 '16 at 20:59












    • @varun - If the directory is empty you can simply do rmdir <dir> but you did not specify whether it is empty therefore I am assuming it is not. You need rm -rf in that case, I made an edit to the code in the answer. Note that rm -rf can be very destructive, I did an if in there for some security but be very careful with forward slashes (/) in names if you are using rm -rf.
      – grochmal
      Aug 13 '16 at 21:11










    • Thanks , It worked. I will keep in my what you suggested about rm -rf
      – Varun
      Aug 13 '16 at 21:15


















    • hey thanks thats worked, I would like one more help, If the newdir is already there i want to remove it and create a new one. for that I just added this , but its not working, I am really sorry for asking silly things, because I am totally new to this. please see the updated question
      – Varun
      Aug 13 '16 at 20:59












    • @varun - If the directory is empty you can simply do rmdir <dir> but you did not specify whether it is empty therefore I am assuming it is not. You need rm -rf in that case, I made an edit to the code in the answer. Note that rm -rf can be very destructive, I did an if in there for some security but be very careful with forward slashes (/) in names if you are using rm -rf.
      – grochmal
      Aug 13 '16 at 21:11










    • Thanks , It worked. I will keep in my what you suggested about rm -rf
      – Varun
      Aug 13 '16 at 21:15
















    hey thanks thats worked, I would like one more help, If the newdir is already there i want to remove it and create a new one. for that I just added this , but its not working, I am really sorry for asking silly things, because I am totally new to this. please see the updated question
    – Varun
    Aug 13 '16 at 20:59






    hey thanks thats worked, I would like one more help, If the newdir is already there i want to remove it and create a new one. for that I just added this , but its not working, I am really sorry for asking silly things, because I am totally new to this. please see the updated question
    – Varun
    Aug 13 '16 at 20:59














    @varun - If the directory is empty you can simply do rmdir <dir> but you did not specify whether it is empty therefore I am assuming it is not. You need rm -rf in that case, I made an edit to the code in the answer. Note that rm -rf can be very destructive, I did an if in there for some security but be very careful with forward slashes (/) in names if you are using rm -rf.
    – grochmal
    Aug 13 '16 at 21:11




    @varun - If the directory is empty you can simply do rmdir <dir> but you did not specify whether it is empty therefore I am assuming it is not. You need rm -rf in that case, I made an edit to the code in the answer. Note that rm -rf can be very destructive, I did an if in there for some security but be very careful with forward slashes (/) in names if you are using rm -rf.
    – grochmal
    Aug 13 '16 at 21:11












    Thanks , It worked. I will keep in my what you suggested about rm -rf
    – Varun
    Aug 13 '16 at 21:15




    Thanks , It worked. I will keep in my what you suggested about rm -rf
    – Varun
    Aug 13 '16 at 21:15












    up vote
    1
    down vote













    There are multiple problems with your script, without completely rewriting it you have to:




    • strip value from any spaces

    • use appServer_version in your script, like in the input file not JbossVersion


    Working:



    file="./app.properties"

    if [ -f "$file" ]
    then
    echo "$file found."

    while IFS='=' read -r key value
    do
    key=$(echo $key | tr '.' '_')
    value=$(echo $value | sed 's/ //g')
    eval "${key}='${value}'"
    done < "$file"

    echo "build_name = " ${build_name}
    echo "build_no = " ${build_no}
    echo "Jboss_version = "${appServer_version}
    echo "Got the value from property file"


    name=${build_name}-
    build=${build_no}-
    Jboss=${appServer_version}

    fileName="${name}${build}${Jboss}"
    echo $fileName
    # mkdir $fileName

    else
    echo "$file not found."
    fi





    share|improve this answer





















    • I was here writing a better way to do it and you beat me by seconds :), A deserved +1
      – grochmal
      Aug 13 '16 at 20:26










    • @grochmal Sorry for that. I normally don't do much with pure bash, but came across this in the review queue. Your second solution is cleaner IMO.
      – Anthon
      Aug 13 '16 at 20:30










    • I actually meant it in a good way, reminds me to keep my guts. As Mark Pilgrim says: the one who makes the specification is not the one who makes the cleaner spec, but the one who delivers the first implementation.
      – grochmal
      Aug 13 '16 at 20:44















    up vote
    1
    down vote













    There are multiple problems with your script, without completely rewriting it you have to:




    • strip value from any spaces

    • use appServer_version in your script, like in the input file not JbossVersion


    Working:



    file="./app.properties"

    if [ -f "$file" ]
    then
    echo "$file found."

    while IFS='=' read -r key value
    do
    key=$(echo $key | tr '.' '_')
    value=$(echo $value | sed 's/ //g')
    eval "${key}='${value}'"
    done < "$file"

    echo "build_name = " ${build_name}
    echo "build_no = " ${build_no}
    echo "Jboss_version = "${appServer_version}
    echo "Got the value from property file"


    name=${build_name}-
    build=${build_no}-
    Jboss=${appServer_version}

    fileName="${name}${build}${Jboss}"
    echo $fileName
    # mkdir $fileName

    else
    echo "$file not found."
    fi





    share|improve this answer





















    • I was here writing a better way to do it and you beat me by seconds :), A deserved +1
      – grochmal
      Aug 13 '16 at 20:26










    • @grochmal Sorry for that. I normally don't do much with pure bash, but came across this in the review queue. Your second solution is cleaner IMO.
      – Anthon
      Aug 13 '16 at 20:30










    • I actually meant it in a good way, reminds me to keep my guts. As Mark Pilgrim says: the one who makes the specification is not the one who makes the cleaner spec, but the one who delivers the first implementation.
      – grochmal
      Aug 13 '16 at 20:44













    up vote
    1
    down vote










    up vote
    1
    down vote









    There are multiple problems with your script, without completely rewriting it you have to:




    • strip value from any spaces

    • use appServer_version in your script, like in the input file not JbossVersion


    Working:



    file="./app.properties"

    if [ -f "$file" ]
    then
    echo "$file found."

    while IFS='=' read -r key value
    do
    key=$(echo $key | tr '.' '_')
    value=$(echo $value | sed 's/ //g')
    eval "${key}='${value}'"
    done < "$file"

    echo "build_name = " ${build_name}
    echo "build_no = " ${build_no}
    echo "Jboss_version = "${appServer_version}
    echo "Got the value from property file"


    name=${build_name}-
    build=${build_no}-
    Jboss=${appServer_version}

    fileName="${name}${build}${Jboss}"
    echo $fileName
    # mkdir $fileName

    else
    echo "$file not found."
    fi





    share|improve this answer












    There are multiple problems with your script, without completely rewriting it you have to:




    • strip value from any spaces

    • use appServer_version in your script, like in the input file not JbossVersion


    Working:



    file="./app.properties"

    if [ -f "$file" ]
    then
    echo "$file found."

    while IFS='=' read -r key value
    do
    key=$(echo $key | tr '.' '_')
    value=$(echo $value | sed 's/ //g')
    eval "${key}='${value}'"
    done < "$file"

    echo "build_name = " ${build_name}
    echo "build_no = " ${build_no}
    echo "Jboss_version = "${appServer_version}
    echo "Got the value from property file"


    name=${build_name}-
    build=${build_no}-
    Jboss=${appServer_version}

    fileName="${name}${build}${Jboss}"
    echo $fileName
    # mkdir $fileName

    else
    echo "$file not found."
    fi






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Aug 13 '16 at 20:24









    Anthon

    59.9k17102163




    59.9k17102163












    • I was here writing a better way to do it and you beat me by seconds :), A deserved +1
      – grochmal
      Aug 13 '16 at 20:26










    • @grochmal Sorry for that. I normally don't do much with pure bash, but came across this in the review queue. Your second solution is cleaner IMO.
      – Anthon
      Aug 13 '16 at 20:30










    • I actually meant it in a good way, reminds me to keep my guts. As Mark Pilgrim says: the one who makes the specification is not the one who makes the cleaner spec, but the one who delivers the first implementation.
      – grochmal
      Aug 13 '16 at 20:44


















    • I was here writing a better way to do it and you beat me by seconds :), A deserved +1
      – grochmal
      Aug 13 '16 at 20:26










    • @grochmal Sorry for that. I normally don't do much with pure bash, but came across this in the review queue. Your second solution is cleaner IMO.
      – Anthon
      Aug 13 '16 at 20:30










    • I actually meant it in a good way, reminds me to keep my guts. As Mark Pilgrim says: the one who makes the specification is not the one who makes the cleaner spec, but the one who delivers the first implementation.
      – grochmal
      Aug 13 '16 at 20:44
















    I was here writing a better way to do it and you beat me by seconds :), A deserved +1
    – grochmal
    Aug 13 '16 at 20:26




    I was here writing a better way to do it and you beat me by seconds :), A deserved +1
    – grochmal
    Aug 13 '16 at 20:26












    @grochmal Sorry for that. I normally don't do much with pure bash, but came across this in the review queue. Your second solution is cleaner IMO.
    – Anthon
    Aug 13 '16 at 20:30




    @grochmal Sorry for that. I normally don't do much with pure bash, but came across this in the review queue. Your second solution is cleaner IMO.
    – Anthon
    Aug 13 '16 at 20:30












    I actually meant it in a good way, reminds me to keep my guts. As Mark Pilgrim says: the one who makes the specification is not the one who makes the cleaner spec, but the one who delivers the first implementation.
    – grochmal
    Aug 13 '16 at 20:44




    I actually meant it in a good way, reminds me to keep my guts. As Mark Pilgrim says: the one who makes the specification is not the one who makes the cleaner spec, but the one who delivers the first implementation.
    – grochmal
    Aug 13 '16 at 20:44










    up vote
    0
    down vote













    to skip #comments or some rubbish in app.properties
    #!/bin/bash



    FILE="./app.properties"

    SEP=
    FILENAME=
    while read -r LINE; do
    LINE=$(echo ${LINE} | sed -rn -e '/=/{/#.*/d;s/[^=]+=([^=]+).*/1/;s/[ ]*//gp}' )
    [[ -n ${LINE} ]] && FILENAME+=${SEP}${LINE} && [[ -z ${SEP} ]] && SEP="-"
    done <"$FILE"

    echo $FILENAME
    #mkdir $FILENAME





    share|improve this answer

























      up vote
      0
      down vote













      to skip #comments or some rubbish in app.properties
      #!/bin/bash



      FILE="./app.properties"

      SEP=
      FILENAME=
      while read -r LINE; do
      LINE=$(echo ${LINE} | sed -rn -e '/=/{/#.*/d;s/[^=]+=([^=]+).*/1/;s/[ ]*//gp}' )
      [[ -n ${LINE} ]] && FILENAME+=${SEP}${LINE} && [[ -z ${SEP} ]] && SEP="-"
      done <"$FILE"

      echo $FILENAME
      #mkdir $FILENAME





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        to skip #comments or some rubbish in app.properties
        #!/bin/bash



        FILE="./app.properties"

        SEP=
        FILENAME=
        while read -r LINE; do
        LINE=$(echo ${LINE} | sed -rn -e '/=/{/#.*/d;s/[^=]+=([^=]+).*/1/;s/[ ]*//gp}' )
        [[ -n ${LINE} ]] && FILENAME+=${SEP}${LINE} && [[ -z ${SEP} ]] && SEP="-"
        done <"$FILE"

        echo $FILENAME
        #mkdir $FILENAME





        share|improve this answer












        to skip #comments or some rubbish in app.properties
        #!/bin/bash



        FILE="./app.properties"

        SEP=
        FILENAME=
        while read -r LINE; do
        LINE=$(echo ${LINE} | sed -rn -e '/=/{/#.*/d;s/[^=]+=([^=]+).*/1/;s/[ ]*//gp}' )
        [[ -n ${LINE} ]] && FILENAME+=${SEP}${LINE} && [[ -z ${SEP} ]] && SEP="-"
        done <"$FILE"

        echo $FILENAME
        #mkdir $FILENAME






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 13 '16 at 22:17









        basilest

        261




        261






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f303243%2fhow-to-create-a-directory-by-combining-two-name%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Morgemoulin

            Scott Moir

            Souastre