How to use variables inside back-quotes

Erel Segal-Halevi

I have a bash script that accepts a parameter "$input" and (among other things) directs it into a program and collects the output.

Currently my line is:

OUTPUT=`./main.exe < $input`

But I get the following error:

$input: ambiguous redirect

What is the correct way to do it?

Kusalananda

Your variable's value probably contains spaces.

You should double quote it:

output=$( ./main.exe <"$input" )

The bash shell requires that the variable, in this context, is quoted and will otherwise perform word-splitting and filename globbing on its value, while other shell may not require this.

Also, note that $input here is the pathname of a file that will be connected to the standard input stream of your program, not an argument to main.exe (I might have misunderstood your text, but never the less). If you want to use $input as a command line argument instead, your command would look like

output=$( ./main.exe "$input" )

Related:

Also:

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to grep a specific line with quotes and then compare something inside it

분류에서Dev

How to use php inside of javascript?

분류에서Dev

How to safely back up files that may be in use?

분류에서Dev

How to use Monit Environment variables?

분류에서Dev

AngularJS - How to use includes with variables?

분류에서Dev

How to use find command with variables

분류에서Dev

How to use double quotes in bash around a directory with spaces

분류에서Dev

How to use toast message inside Thread in Android

분류에서Dev

How to use a gulp plugin inside a gulp plugin?

분류에서Dev

optparse main function, how to use the options inside

분류에서Dev

How to use regex inside exec with find?

분류에서Dev

How to use param values inside for loop

분류에서Dev

How to Pass variables inside functions using new method

분류에서Dev

How can I echo nested variables inside a for loop?

분류에서Dev

How to use variables to create elements in an array in BASH?

분류에서Dev

how to use system environment variables in boto

분류에서Dev

How to use long variables name in Makefile?

분류에서Dev

How do I use URL directories as variables?

분류에서Dev

How to turn azure deployment warning modal "deployment environment in use" back on?

분류에서Dev

Dollar sign interpolation inside quotes in bash

분류에서Dev

Ignoring a Rogue quote inside Double quotes

분류에서Dev

Double quotes and variables in Sed - Unknown expression?

분류에서Dev

Escaping double quotes for variables in bash and qmake

분류에서Dev

Escaping double quotes for variables in bash and qmake

분류에서Dev

Use sed with back references

분류에서Dev

How to use a virtual keyboard inside Libre Office Writier?

분류에서Dev

How do I use an array variable inside an array of structures?

분류에서Dev

How to use computed method inside foreach in knockout.js

분류에서Dev

How do I use service methods inside an @Secured expression?

Related 관련 기사

  1. 1

    How to grep a specific line with quotes and then compare something inside it

  2. 2

    How to use php inside of javascript?

  3. 3

    How to safely back up files that may be in use?

  4. 4

    How to use Monit Environment variables?

  5. 5

    AngularJS - How to use includes with variables?

  6. 6

    How to use find command with variables

  7. 7

    How to use double quotes in bash around a directory with spaces

  8. 8

    How to use toast message inside Thread in Android

  9. 9

    How to use a gulp plugin inside a gulp plugin?

  10. 10

    optparse main function, how to use the options inside

  11. 11

    How to use regex inside exec with find?

  12. 12

    How to use param values inside for loop

  13. 13

    How to Pass variables inside functions using new method

  14. 14

    How can I echo nested variables inside a for loop?

  15. 15

    How to use variables to create elements in an array in BASH?

  16. 16

    how to use system environment variables in boto

  17. 17

    How to use long variables name in Makefile?

  18. 18

    How do I use URL directories as variables?

  19. 19

    How to turn azure deployment warning modal "deployment environment in use" back on?

  20. 20

    Dollar sign interpolation inside quotes in bash

  21. 21

    Ignoring a Rogue quote inside Double quotes

  22. 22

    Double quotes and variables in Sed - Unknown expression?

  23. 23

    Escaping double quotes for variables in bash and qmake

  24. 24

    Escaping double quotes for variables in bash and qmake

  25. 25

    Use sed with back references

  26. 26

    How to use a virtual keyboard inside Libre Office Writier?

  27. 27

    How do I use an array variable inside an array of structures?

  28. 28

    How to use computed method inside foreach in knockout.js

  29. 29

    How do I use service methods inside an @Secured expression?

뜨겁다태그

보관