Linux script - Crazy results

Here is my script:

#
# Capture the current directory.
export -p CurrentDir="`pwd`"
echo $CurrentDir
#
# Capture the new directory name in the form YYYYMMDD.
export -p DateDir="`date +"%Y%m%d"`"
echo $DateDir
#
# Store the desired target directory.
export -p TargetDir="/staging/VCproc/TestIncoming"
echo $TargetDir
#
# Create the directory to move yesterday's file to.
cd $TargetDir
#mkdir $DateDir
#
#
cd $CurrentDir

Here are the (unwanted) results:

>. exec_move_yesterday_files_from_incoming.sh
/staging/VCproc/application/dm
20090724
/staging/VCproc/TestIncoming
: No such file or directoryTestIncoming
: No such file or directoryapplication/dm

What am I doing wrong? Thanks in advance.

The output does look odd. What shell is the script using? I notice that the first x characters are missing from the path in the no such file errors.

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

Agreed. The script does not seem to match the output.
Maybe funny characters in the directory names (such as screen delete characters)?

To see any strange characters in filenames:

ls -lad * | sed -n l

What is "export -p" ?

When I run it as BASH it gives different (but still undesired) results.

Code:

>cat exec_move_yesterday_files_from_incoming.sh
#
# Capture the current directory.
export -p CurrentDir="`pwd`"
echo $CurrentDir
#
# Capture the new directory name in the form YYYYMMDD.
export -p DateDir="`date +"%Y%m%d"`"
echo $DateDir
#
# Store the desired target directory.
export -p TargetDir="/staging/VCproc/TestIncoming"
echo $TargetDir
#
# Create the directory to move yesterday's file to.
cd $TargetDir
#mkdir $DateDir
`pwd`
#
#
cd $CurrentDir
`pwd`

Results:

VCproc@mpslx093[client]/staging/VCproc/application/dm
>bash exec_move_yesterday_files_from_incoming.sh
/staging/VCproc/application/dm
20090724
/staging/VCproc/TestIncoming
: No such file or directoryrom_incoming.sh: line 15: cd: /staging/VCproc/TestIncoming
: No such file or directoryrom_incoming.sh: line 17: /staging/VCproc/application/dm
: No such file or directoryrom_incoming.sh: line 20: cd: /staging/VCproc/application/dm
: No such file or directoryrom_incoming.sh: line 21: /staging/VCproc/application/dm

Not sure what is going on, but it looks like there is something wrong with the paths themselves. When the error is displayed, it is overwriting the first part of the error with the last. This implies that there may be some wonky character at the end of the path.

Do you know of anything odd in your environment that might be causing this? I copied your code and it didn't do this on my system.

After a bit of research into:

export -p

In a POSIX shell "export -p" lists the currently exported values.
It does nothing else, even with parameters after the "export -p".

Compare:
# Proper use of export
unset hello
export hello="hello"
export -p | grep "hello"
# Improper use of export
unset hello
export -p hello="hello"
export -p | grep "hello"

Suggest you remove the "export -p" which precedes each assignment of environment variables in your script because it is stopping the assignment taking place. Besides which there is no point to using "export" in this shell context.