0

GOAL: As the title suggests i'm needing to pass the results of a function to a variable. Specifically, LASTLOG() { wevtutil qe "$WINLOG" //c:1 //rd:.ture //f:text } This primary command is wevtutil qe "$WINLOG" //c:1 //rd:.ture //f:text.

ISSUE: Originally I did the following LASTLOG=$(wevtutil qe "$WINLOG" //c:1 //rd:.ture //f:text), but i've been informed that passing cmds to variables is not best practice so I created a function. LASTLOG() { wevtutil qe "$WINLOG" //c:1 //rd:.ture //f:text }--however I cant seem to pass the ouput of the function to a variable for later comparison.

dex
  • 11
  • 6
  • who said passing commands to variables is not best practice? how have you tried passing the function call (basically a 'command') to a variable? – markp-fuso Jun 25 '20 at 15:55
  • I know that the version with the ```var=$(cmd)```, works but b/c this will be public prj I want to use best practice. Idk which bash guide stated it but "functions are for holding commands, variables are for holding data" . I think what I will try is calling the func. the piping the output of the call into a variable--seeing as "cmds" create "data" hopefully my logic is ok. – dex Jun 25 '20 at 16:49
  • 1
    so if you have `function LASTLOG { wevtutil qe "$WINLOG" //c:1 //rd:.ture //f:text ;}` in your script, have you tried the variable assignment with `lastlog=$(LASTLOG)` ? – lab9 Jun 25 '20 at 18:19
  • I have not and will do so, thank you – dex Jun 25 '20 at 18:38

0 Answers0