I am trying to store a cat output into a variable and then trying to echo it. and then I would like to kill the process.
#!/bin/bash
var = $(cat tmp/pids/unicorn.pid)
echo $var
sudo kill -QUIT $var
Please if anyone can tell where I am going wrong
To store the output of a command in a variable, you can use the shell command substitution feature in the forms below: variable_name=$(command) variable_name=$(command [option ...] arg1 arg2 ...) OR variable_name='command' variable_name='command [option ...] arg1 arg2 ...'
The EOF operator is used in many programming languages. This operator stands for the end of the file. This means that wherever a compiler or an interpreter encounters this operator, it will receive an indication that the file it was reading has ended.
Cat is short for concatenate. This command displays the contents of one or more files without having to open the file for editing. In this article, learn how to use the cat command in Linux.
Variable assignments in bash should not have any spaces before or after the equal sign. It should be like this:
#!/bin/bash
var=$(cat tmp/pids/unicorn.pid)
echo "$var"
Which can be written more idiomatically as
#!/bin/bash
var=$(< tmp/pids/unicorn.pid)
echo "$var"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With