11

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
  • 597
  • 1
  • 8
  • 22

1 Answers1

35

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
  • 32,226
  • 12
  • 81
  • 108
  • 8
    +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