-1

I would like to ask you how can I hide echo from my function but still use its echo as a variable for next processing.

My code is:

function str_str {
local str
str="${1#*${2}}"
str="${str%%$3*}"
echo -n "$str"
}

mystr=$(cat /etc/logrotate.conf)
str_str "$mystr" "access.log" "}"

OKACCESS=$(str_str "$mystr" "access.log" "}" | grep -e "daily" -e "size" -e "rotate" -e "create" -e "weekly" -c)
echo $OKACCESS

When I remove the:

echo -n "$str"

I can not use it as a variable for OKACCESS, which returns 0, should return 4 (works with echo not hidden or passed to dev>null).

How do I hide output of the function without limiting the definition of OKACCESS variable?

Thank you for help.

E:

What I am trying to do:

When I execute my current script, its output is:

[root@env test]# ./tester.sh
{
        missingok
        daily
        rotate 10
        create 0664 jboss jboss
        postrotate
        /usr/bin/kill -s SIGHUP `cat /var/run/syslogd.pid`
        endscript
        dateext
4

When I remove the "echo -n "$str"" part, I get this:

0

and I need this:

4
Filip Kraus
  • 2,714
  • 2
  • 14
  • 16
  • I'm sorry, but it's not at all clear what you are trying to accomplish and which part of it that you are having a problem with. Could you please [edit] your question to explain what you are trying to do? – tripleee Sep 16 '15 at 11:31
  • Done :) I hope this helps. – Filip Kraus Sep 16 '15 at 11:35
  • And you have copy/pasted this code without understanding what it does? If your function doesn't produce any output, `grep` will not find any hits. – tripleee Sep 16 '15 at 11:38
  • I understand it, what I am looking for is to hide the output from the echoing it during the execution, not removing it completely. – Filip Kraus Sep 16 '15 at 11:42
  • I am sorry I am not sure if I understand what you mean. – Filip Kraus Sep 16 '15 at 11:45

1 Answers1

2

This will hide the output of the first function call:

str_str "$mystr" "access.log" "}" > /dev/null
John Zwinck
  • 239,568
  • 38
  • 324
  • 436