# Shell transmission lines to the function.



## valsorym (Aug 7, 2011)

Hi all.
I have a problem. I have shell script:


```
#!/bin/sh
# example.

logFile() {
	if [ ${#} -eq 0]; then
		exit
	fi # end if().
	
	if [ ${1} = 'NULL' ]; then
		echo '' > $HOME/.mylog
	else
		echo ${1} >> $HOME/.mylog
	fi # end if().
} # end logFile function.


logFile NULL
logFile 'Hello world'

# end file.
```
If I send message how:

```
logFile 'It is message'
```

I have error:

```
[: Configuring: unexpected operator
```

If I send message how:

```
logFile ${msg='It is message'}
```
I do not have error. But my logfile has next string:

```
It
```
If I send message how:

```
logFile 'It_is_message'
```
or

```
logFile ${msg='It_is_message'}
```
All ok.

How can I fix it?


----------



## wblock@ (Aug 7, 2011)

Quote your variables:

```
if [ "${1}" = 'NULL' ]; then
		echo '' > $HOME/.mylog
	else
		echo "${1}" >> $HOME/.mylog
	fi # end if().
```

As suggestions, don't use tabs for indenting.  Unless you have your editor set to show them as less than 8 spaces, I guess.  Also, that comment on the "fi" is visual noise that makes the code harder to read.


```
if [ "${1}" = 'NULL' ]; then
    echo '' > $HOME/.mylog
  else
    echo "${1}" >> $HOME/.mylog
  fi
```


----------



## valsorym (Aug 7, 2011)

Yes, thanks, it works.



> Originally Posted by *wblock*.
> As suggestions, don't use tabs for indenting. Unless you have your editor set to show them as less than 8 spaces, I guess. Also, that comment on the "fi" is visual noise that makes the code harder to read.



In Windows I used Notepad + + and installed instead of TAB - 4  space. In FreeBSD, I use the vi editor. When you start the vi editor, I ask:

```
: set tabstop = 4
```

The scenario that presented higher - I typed it right in your browser. Because not care about the number of indents. Just do not care about design.

But, thank you very much.


----------

