12

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

3
  • Are you missing slash from begin of file name? Commented Oct 22, 2016 at 13:30
  • 2
    Don't put space around =. It should be var=$(cat tmp/pids/unicorn.pid). Also provide valid path. Commented Oct 22, 2016 at 13:32
  • @sat tmp/pids/unicorn.pid is a valid path; it might not be the right path, but that isn't relevant to this question. Commented Oct 22, 2016 at 13:57

1 Answer 1

38

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"
Sign up to request clarification or add additional context in comments.

1 Comment

+1 This saved my day: "Variable assignments in bash should not have any spaces before or after the equal sign"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.