1

SO i have a Bash Script like this and goal is to determine the path of an executable file and i want to print it, here is what i'm doing

#!/bin/bash exepath=which exe echo "$exepath" 

Now this instead of printing path its starting the exe file in my system, how do i print the path stored in exepath variable.

4
  • 1
    You are looking for command substitution. Commented Jan 18, 2021 at 10:33
  • I understood. Follow this answer. Commented Jan 18, 2021 at 10:42
  • Thank you so much this is exactly what i was looking for. Commented Jan 18, 2021 at 10:51
  • Is outputting the pathname all you want to do in your script? In that case, the variable is not needed and you could do it with just command -v exe. Commented Jan 18, 2021 at 11:35

1 Answer 1

2

Instead of

exepath=which exe 

(this command just runs exe, previously setting the environment variable exepath to literal value which)

you should use

exepath=`which exe` 

or

exepath=$(which exe) 
1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.