[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] export
From: |
Pierre Gaston |
Subject: |
Re: [Help-bash] export |
Date: |
Sat, 4 Feb 2017 03:31:53 +0200 |
On Sat, Feb 4, 2017 at 3:05 AM, Val Krem <address@hidden> wrote:
> Hi all,
>
> I am trying to export a variable from a shell script. The script is
> working well if I run my script without an argument ( $#=0). I am
> inter4ested in to export the variable if the $# -ge 1 but did not work
> for me. Below is my my "broken" script.
>
>
> ######################### mtest.sh ##############################
> #############
>
> #!/bin/bash
>
> ftmp=$(date +%m%Y);export ftmp # ftmp= 022017
> mp=/val/data/
>
> flag=$1; export flag
> nwork=$2; export nwork
> narg=$#; export narg
>
>
> if [ ${narg} -eq 0 ]; then
> if [ ! -d "${mp}"/"${ftmp}" ]; then
> mkdir "${mp}"/"${ftmp}"
> fi
> mp2="${mp}"/"${ftmp}"; export mp2
>
> elif [ "${narg}" -ge 1 ] && [ "${flag}" != "-t" ]; then
> echo "illegal option!"
> exit 1
> else
>
> if [ "${narg}" -eq 2 ] && [ "${flag}" == "-t" ]; then
> if [ ! -d ${mp}/${ftmp}/${nwork} ]; then
> mkdir ${mp}/${ftmp}/${nwork}
> fi
> mp2=${mp}/${ftmp}/${nwork} ; export mp2
> fi
> fi
> echo "end of testing"
> ##############################################################
>
>
> 1. if I execute ./mtest.sh
> I am getting : mp2= /val/data/022017
>
> 2. if I execute with ./mtest -t tdat
> still I am getting mp2= /val/data/022017
>
> but I want to get mp2= /val/data/tdat/022017.
>
> I would appreciate if you help me out here
>
> thank you in advance
>
> You simply can't do that running a regular script, see
http://mywiki.wooledge.org/BashFAQ/060
What you see is probably the result of having set mp2 at some point, if you
unset it and run your script again you will see it doesn't change the value
of mp2