Question: I'm trying to send the output of a command to our syslog and this is what I have so far.

```
#!/bin/bash
log()
{
    logger -s -t $(basename $0) "$@"
}

/bin/echo "test" 2>&1 | (log)

```

and this works perfectly !

```
[root@server bin]# sh /var/tmp/script.sh 
script.sh: test

```

However when I try to append a string to the beginning of the log message, it fails to work !

```
#!/bin/bash
log()
{
    logger -s -t $(basename $0) "DEBUG: $@"
}

/bin/echo "test" 2>&1 | (log)

```

This is the output

```
[root@server bin]# sh /var/tmp/script.sh
script.sh: DEBUG:

```

How can I unpack the $@/$\* variable and also append a prefix to the log message without losing the stdout of the original command?

Answer: 
This is the documented behaviour:

> 
> message
> 
> 
> Write this message to the log; if not specified, and the `-f` flag is not provided, standard input is logged.
> 
> 
> 

Fortunately, you can add the needed information to the standard input of the logger:

```
log()
{
    {
        printf "DEBUG: $@"          # Prepends the prefix.
        cat                         # Outputs the original input.
    } | logger -s -t $(basename $0)
}

```
Passing arguments to a function which can be used as `$1` or `$@` is not the same as reading `stdin`.

You will have to fetch the data from `stdin` first. The following might not be the ideal solution but gives you a hint:

```
#!/bin/bash
log()
{
    read INPUT
    logger -s -t $(basename $0) "DEBUG: $INPUT"
}

echo "test" | (log)

```