10

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

Sumeet Masih
  • 577
  • 1
  • 8
  • 22

1 Answers1

29

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"
user000001
  • 30,389
  • 12
  • 73
  • 103
  • 6
    +1 This saved my day: "Variable assignments in bash should not have any spaces before or after the equal sign" – Hem Nov 27 '18 at 18:00