store a result of a command into a variable using csh

thicksauce

I'm trying to store a result of a command into a variable so I can display it nicely along with some text in one long not have it display the output and then newline then my text, in my csh script.

#! /bin/csh -f


if ("$1" == "-f" && $#argv == 1 ) then
    grep 'su root' /var/adm/messages.[0-9] | cut -c 21-250
    grep 'su root' /var/adm/messages
else if( $#argv >  0 ) then
    echo "Usage : [-f]"
else
  grep 'su root' /var/adm/messages.[0-9] /var/adm/messages | wc -l
  printf "failed su attempts between Nov 02 and Oct 28\n"
endif

this command in the script

  grep 'su root' /var/adm/messages.[0-9] /var/adm/messages | wc -l

gives me 21 when i run it, and i want 21 to be stored in a variable.

so i can just display the output of

21 failed su attempts between Nov 02 and Oct 28

and not

21
failed su attempts between Nov 02 and Oct 28

or if theres an easier way that doesn't involve variables open to that too.

Elliott Frisch

You can use set and backticks (``). Something like

set count=`grep 'su root' /var/adm/messages.[0-9] /var/adm/messages | wc -l`
printf "$count failed su attempts between Nov 02 and Oct 28\n"

or

printf "%s failed su attempts between Nov 02 and Oct 28\n" "$count"

or without a variable, like

printf "%s failed su attempts between Nov 02 and Oct 28\n" \
    `grep 'su root' /var/adm/messages.[0-9] /var/adm/messages | wc -l`

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

store a result of a command into a variable using csh

From Dev

Store the result of a command in a variable

From Dev

Store Result of SVN Command in Variable

From Dev

how to store result of tail command in variable?

From Dev

Get the result of a WMIC command and store it in a variable

From Dev

Shell script -- how to store curl command WITH variables result into another variable?

From Dev

Run a command in GNU and BSD Makefile and store the result into a variable

From Dev

Run a command in GNU and BSD Makefile and store the result into a variable

From Dev

Store column result in variable

From Dev

Store function result into variable

From Dev

store into variable a sudo result

From Dev

Store function result into variable

From Dev

How to store result of stored procedure in a variable using SQL Server

From Dev

Can I store the result of Fetch in a global variable using JavaScript?

From Dev

Store the whole query result in variable using postgresql Stored procedure

From Dev

Why store the result of getElementById() to a variable instead of using the function everytime?

From Dev

How to store SQL query result in a variable using PHP?

From Dev

store MySQL SELECT result in php variable using Prepared statements

From Dev

How do I set a variable to a command's output in csh?

From Dev

Assign result of command in a variable

From Dev

CMD: Binding result of command to a variable and using it in the next call

From Dev

How to store multiple lines of command output to a variable using JSch

From Dev

Cannot store result into variable SQL

From Dev

Store the assert failure result in a variable

From Dev

Store the result of a Dynamic Query in a variable

From Dev

Store into variable result of function VBA

From Dev

Store cmd Find result to a variable

From Dev

Sed Fails to store the result into a variable

From Dev

How to store a query result in a variable

Related Related

  1. 1

    store a result of a command into a variable using csh

  2. 2

    Store the result of a command in a variable

  3. 3

    Store Result of SVN Command in Variable

  4. 4

    how to store result of tail command in variable?

  5. 5

    Get the result of a WMIC command and store it in a variable

  6. 6

    Shell script -- how to store curl command WITH variables result into another variable?

  7. 7

    Run a command in GNU and BSD Makefile and store the result into a variable

  8. 8

    Run a command in GNU and BSD Makefile and store the result into a variable

  9. 9

    Store column result in variable

  10. 10

    Store function result into variable

  11. 11

    store into variable a sudo result

  12. 12

    Store function result into variable

  13. 13

    How to store result of stored procedure in a variable using SQL Server

  14. 14

    Can I store the result of Fetch in a global variable using JavaScript?

  15. 15

    Store the whole query result in variable using postgresql Stored procedure

  16. 16

    Why store the result of getElementById() to a variable instead of using the function everytime?

  17. 17

    How to store SQL query result in a variable using PHP?

  18. 18

    store MySQL SELECT result in php variable using Prepared statements

  19. 19

    How do I set a variable to a command's output in csh?

  20. 20

    Assign result of command in a variable

  21. 21

    CMD: Binding result of command to a variable and using it in the next call

  22. 22

    How to store multiple lines of command output to a variable using JSch

  23. 23

    Cannot store result into variable SQL

  24. 24

    Store the assert failure result in a variable

  25. 25

    Store the result of a Dynamic Query in a variable

  26. 26

    Store into variable result of function VBA

  27. 27

    Store cmd Find result to a variable

  28. 28

    Sed Fails to store the result into a variable

  29. 29

    How to store a query result in a variable

HotTag

Archive