On Thu, May 26, 2011 at 11:50 AM, Paul Davies <[email protected]> wrote:
> Hi,
> I was working on a shell code , which detects file names with
> space in between in the present directory. One unusual behaviour I
> found in this particular context is that the command `var="$var
> $var2"' is not working. The link to code is http://pastebin.com/wDDp5NEv
I don't understand what you are trying to do. The following works for me.
$ export var="a b c"
$ export var2="d e f"
$ export var="$var $var2"
$ echo $var
a b c d e f
BTW, was this what you were trying to do?
for i in *; do
echo $i | grep " "
done
Anyways, here is your way of doing it.
#!/bin/bash
tmp=""
for file1 in `ls`; do
# echo $file1
if [ -e "$file1" ]; then
tmp=""
else
if [ "$tmp" == "" ]; then
tmp="$file1"
else
tmp="$tmp $file1" #This is not working
fi
if [ -e "$tmp" ]; then
echo "$tmp"
tmp=""
fi
fi
done
When you are concatenating the filename, the first time you add a
token, it is prepended with a space which is why your line 9 fails
(also, you should use -- if test -e "$tmp").
HTH,
Sharad
--
Mailing list guidelines and other related articles: http://lug-iitd.org/Footer