0

Becuase I need to make sure I run authentication for my nohup commands I need the real command I want to run to be in a string in here:

nohup sh -c 'echo $SU_PASSWORD | /afs/cs/software/bin/reauth; python -u $RUN_CMD' > $PWD/nohup.out$SLURM_JOBID &

I tried creating the string and storing it in the variable $RUN_CMD e.g.

export RUN_CMD='${!HOME}/diversity-for-predictive-success-of-meta-learning/div_src/diversity_src/experiment_mains/main_diversity_with_task2vec.py --manual_loads_name diversity_ala_task2vec_delauny > $OUT_FILE 2> $ERR_FILE'

but I can't make it work. How do I do it? My attempts:

(metalearning_gpu) brando9~ $ export RUN_CMD='${!HOME}/diversity-for-predictive-success-of-meta-learning/div_src/diversity_src/experiment_mains/main_diversity_with_task2vec.py --manual_loads_name diversity_ala_task2vec_delauny > $OUT_FILE 2> $ERR_FILE'
(metalearning_gpu) brando9~ $ echo $RUN_CMD
${!HOME}/diversity-for-predictive-success-of-meta-learning/div_src/diversity_src/experiment_mains/main_diversity_with_task2vec.py --manual_loads_name diversity_ala_task2vec_delauny > $OUT_FILE 2> $ERR_FILE
(metalearning_gpu) brando9~ $ export RUN_CMD=$(echo '$HOME/diversity-for-predictive-success-of-meta-learning/div_src/diversity_src/experiment_mains/main_diversity_with_task2vec.py --manual_loads_name diversity_ala_task2vec_delauny > $OUT_FILE 2> $ERR_FILE')
(metalearning_gpu) brando9~ $ echo $RUN_CMD
$HOME/diversity-for-predictive-success-of-meta-learning/div_src/diversity_src/experiment_mains/main_diversity_with_task2vec.py --manual_loads_name diversity_ala_task2vec_delauny > $OUT_FILE 2> $ERR_FILE
(metalearning_gpu) brando9~ $ export RUN_CMD=$(echo '${!HOME}/diversity-for-predictive-success-of-meta-learning/div_src/diversity_src/experiment_mains/main_diversity_with_task2vec.py --manual_loads_name diversity_ala_task2vec_delauny > $OUT_FILE 2> $ERR_FILE')
(metalearning_gpu) brando9~ $ echo $RUN_CMD
${!HOME}/diversity-for-predictive-success-of-meta-learning/div_src/diversity_src/experiment_mains/main_diversity_with_task2vec.py --manual_loads_name diversity_ala_task2vec_delauny > $OUT_FILE 2> $ERR_FILE
(metalearning_gpu) brando9~ $ export RUN_CMD=(eval '$HOME/diversity-for-predictive-success-of-meta-learning/div_src/diversity_src/experiment_mains/main_diversity_with_task2vec.py --manual_loads_name diversity_ala_task2vec_delauny > $OUT_FILE 2> $ERR_FILE')
(metalearning_gpu) brando9~ $ echo $RUN_CMD
eval

related:

  • Also, why are you using '${!HOME} instead of just $HOME? $HOME isn't an array, and AFAIK, ${! is only useful for getting indices from an array or getting a list of variable names beginning with a prefix. BTW, variable expansion doesn't happen inside single quotes anyway. – cas Nov 23 '22 at 23:03
  • @cas I don't understand why the home variable isn't being expanded and saved in the variable I want. – Charlie Parker Nov 24 '22 at 01:27
  • @cas I am already using the sh -c ... In my code. What doesn't seem to work is the variable expansions – Charlie Parker Nov 24 '22 at 01:29
  • Variables don't expand inside single quotes. BTW, back to the ! thing - the other use for it is variable indirection, and i can't see any reason why you'd want that in this context (or with $HOME at all). IMO, you should stop what you're doing and start again from scratch, you need to rethink your approach. Start by using an array rather than a scalar variable. Better yet, use a better language, one where you can avoid all the horrors and PITA-ness of shell quoting - perl or python would be good choices, and you already seem to know python. – cas Nov 24 '22 at 01:47
  • (cont.) Stop thinking of shell as a programming language. It looks a little like one, but it's not. It's a command line interpreter with some scripting capabilities. Even with all the enhancements and features added by fancy versions like bash or zsh, it's still not a programming language....all that those extra fancy features do is slightly disguise how shitty it is as a programming language, but they do nothing to change the fact that fundamentally it is a shit language. Don't use it for anything more than simple - or, at most, moderately complex - tasks. – cas Nov 24 '22 at 01:54
  • I've done some extraordinarily complex things with shell in my time. And every single one of those would have been much easier to do in any other language, and the result would be better, faster, and more robust. It would also be much shorter, and much easier to read, understand, and modify. Ultimately, trying to do anything complex in shell is a mistake. – cas Nov 24 '22 at 01:56

0 Answers0