Stupid question: if [ "$i" == `$(cat ${LOGFILESSHD} | grep "${i}" )` ] ; then
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Stupid question: if [ "$i" == `$(cat ${LOGFILESSHD} | grep "${i}" )` ] ; then
Code:
cat /var/log/auth.log | grep "blabla blabla blabla" | while read i ; do
echo "**$i**"
allre=`$(cat ${LOGFILESSHD} | grep "${i}" )`
...
the problem is that allre is always egal to nothing
It would work if I had no spaces in "blabla blabla blabla"
and with writing
allre="$(cat ${LOGFILESSHD} | grep ${i} )"
with ".
I have a problem, very stupid , sorry, with " ...
Could somebdy be kind for giving the solution ? I bump bump bump ... on that bash but cannot find it... no idea really
this syntax is wrong. the backticks and the syntax $(...) are (almost) equivalent for command substitution. If you use them together you can get unpredictable results. Indeed, at first the command inside $(...) is evaluated, then the result is evaluated again as a command, because of the embedding backticks. You stated that it works using double quotes: what prevent you from using them?
Note that if you're trying to access the variable outside the while loop, it will result empty. This is because the while loop is called after a pipe, hence in its own subshell with its own local variables. Once the subshell is closed, the variables are lost.
To prevent this behavior, use process substitution, e.g.
Code:
while read i ; do
echo "**$i**"
allre=`$(cat ${LOGFILESSHD} | grep "${i}" )`
done < <(cat /var/log/auth.log | grep "blabla blabla blabla")
this syntax is wrong. the backticks and the syntax $(...) are (almost) equivalent for command substitution. If you use them together you can get unpredictable results. Indeed, at first the command inside $(...) is evaluated, then the result is evaluated again as a command, because of the embedding backticks. You stated that it works using double quotes: what prevent you from using them?
Note that if you're trying to access the variable outside the while loop, it will result empty. This is because the while loop is called after a pipe, hence in its own subshell with its own local variables. Once the subshell is closed, the variables are lost.
To prevent this behavior, use process substitution, e.g.
Code:
while read i ; do
echo "**$i**"
allre=`$(cat ${LOGFILESSHD} | grep "${i}" )`
done < <(cat /var/log/auth.log | grep "blabla blabla blabla")
hi, thank you hence this should maybe be withotut the $ to make it as command:
Code:
while read i ; do
echo "**$i**"
allre=`cat ${LOGFILESSHD} | grep "${i}" `
done < <(cat /var/log/auth.log | grep "blabla blabla blabla")
This syntax is specific to process substitution. For details and some more examples, have a look at chapter 22 of the Advanced Bash Scripting Guide.
Quote:
Ah, still in the same subject, I also get this < pipeline problem:
Code:
ls -tr | tail -n 1 | xargs mplayer
cannot work when the filename has some spaces...
You can try
Code:
ls -tr -Q | tail -n 1 | xargs mplayer
The -Q option embeds file names in double quotes, so that when it is passed as argument to xargs the blank space is correctly interpreted by the shell.
Hmmm... can you explain in real words what you are trying to achieve by this command? What is the expected output and what exactly the problem is? Error messages? Unexpected behavior? Can you provide a real example?
At a first glance, it does not make sense. In the first version - without double quotes - it assigns to the variable essai the output of the command enclosed in $(...) then echoes the value of essai. The second version - with double quotes - assigns the output of the command concatenated with the string " ; echo something", where something is the value of essai. I miss what's your aim and what the problem is, sorry.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.