0

word2018 FILE_2018 > FILE_2018.out &

this works OK for me in bin/bash, terminal, konsole, BASH

I have an text-file script in #!/bin/bash, where I run this variable CMD and it works in CSH, but not in BASH.

CMD="word${year} ${FILE_version.txt} > ${FILE_version.out} &"

word2018 - system alias defined/sourced from other location
word - static name
2018 - variable (can be any number 2015, 2022,....)
FILE_version - variable (can be - FILE_2015, FILE_2022,...)

csh -c "$CMD" ...works OK
bash -c "$CMD" ...NOT working, command word2018 not found

any advice, help? I would appreciate very well

2
  • alias_name = test tries to run alias_name with = and test etc. as arguments, probably not what you want. Commented Feb 17, 2022 at 16:56
  • 2
    Trying to store commands in variables tends not to work very well (see BashFAQ #50: "I'm trying to put a command in a variable, but the complex cases always fail!" and many previous questions here). Variables are really for storing data, not executable code. As for the example code in this question, it has so many problems it's hard to tell what're the real problems and what's just sloppy summarization. Commented Feb 17, 2022 at 18:34

1 Answer 1

1

Just call $CMD

testABC(){
   echo "arg: $1"
}
alias_name=test
#....system alias
var1=ABC
var2=123

CMD="${alias_name}${var1} ${var2}"
echo CMD: $CMD

$CMD

result:

CMD: testABC 123
arg: 123
Sign up to request clarification or add additional context in comments.

2 Comments

it doesnt work........
Works fine on Mint 20.3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.