How to Force command substitution evaluation in bash?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to Force command substitution evaluation in bash?
# 8  
Old 03-29-2016
Quote:
Originally Posted by siegfried
Yes! As I you inferred: $(BackupRecords --log) very similar to $(date +'%Y %b %d %H:%M:%ss'). If I call it too often, I get different log files (which is usually what I want).

However, in this case, I want the same log file for multiple uses within the same script. How can I evaluate $(BackupRecords --log) only once at the beginning of my script once and use it multiple times later in the script?

Thanks
Siegfried
You're missing the point. The code you have does call BackupRecords --log once at the start of your script and uses the string returned by that call throughout the rest of your script. Therefore, the string returned by that command must contain something that is re-evaluating the date every time $BUPLOG is evaluated.

If you won't show us the code for BackupRecords, it is REALLY REALLY hard for us to tell you how to fix it to do what you want.
# 9  
Old 03-29-2016
Set BUPLOG to be readonly by doing typeset -x -r BUPLOG=$(BackupRecords --log "$src")so the script will throw an error every time it's changed...
# 10  
Old 03-29-2016
Quote:
Originally Posted by shamrock
Set BUPLOG to be readonly by doing typeset -x -r BUPLOG=$(BackupRecords --log "$src")so the script will throw an error every time it's changed...
We have seen the script. There is nothing in it that changes BUPLOG after it is initially set. As I have said before, BUPLOG must be a string something like:
Code:
BackupLog$(date +'%Y%m%d%H%M%S')

so when $BUPLOG is expanded it yields a value based on the current time; not the time when BackupRecords --log was executed at the start of the script.
# 11  
Old 03-31-2016
RudiC:
I use BUPLOG twice and that is the problem:
Using BUPLOG twice means I call $(BackupRecords --log "$src") twice which means I get two different log file names. And remember, $(BackupRecords --log "$src") is identical to "$(date +'%Y%b%d%H%M%s')".
I get the same results with BackupRecords --log "$src" and "$(date +'%Y%b%d%H%M%s')": multiple file names. So how can I store the current date and time in an environment variable once and use the environment variable multiple times and not have it change.

Thanks
Siegfried
# 12  
Old 03-31-2016
Quote:
Originally Posted by siegfried
RudiC:
I use BUPLOG twice and that is the problem:
Using BUPLOG twice means I call $(BackupRecords --log "$src") twice which means I get two different log file names. And remember, $(BackupRecords --log "$src") is identical to "$(date +'%Y%b%d%H%M%s')".
I get the same results with BackupRecords --log "$src" and "$(date +'%Y%b%d%H%M%s')": multiple file names. So how can I store the current date and time in an environment variable once and use the environment variable multiple times and not have it change.

Thanks
Siegfried
Expanding $BUPLOG twice DOES NOT invoke BackupRecords --log "$src" twice.

I repeat for at least the third time: Please show us the code that implements your BackupRecords utility so we can help you fix it to return an unchanging backup file pathname!
# 13  
Old 03-31-2016
Quote:
Originally Posted by siegfried
.
.
.
Using BUPLOG twice means I call $(BackupRecords --log "$src") twice
.
.
.
No. export BUPLOG=$(BackupRecords --log "$src") assigns or defines the variable, using or expanding it like $BUPLOG does NOT change it.

I have to second Don Cragun's request for the script/source.

Unless you show what you're doing, further help won't be possible.
# 14  
Old 04-15-2016
RudiC:
I do use it (BUPLOG) over again and the problem is that each time I use it gets a new time and I get a new log file name. I was hoping that the value of BUPLOG would be frozen in the initial export command and I would get same value every time I use $BUPLOG but this is not the sdfsdf. Remember: all "BackupRecords.exe --log" is doing is returning the current time.
Is there anyway I can force the execution of "BackupRecords.exe --log" to happen only once during the export command?

Thanks
Siegfried
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Evaluation of test command

Could somebody please explain to me why and how the highlighted line(s) (?) of code puts the "test" evaluation into "result" and then to $enable_static ? Or does not ? I did comment out the original code and changed it to what I feel is less cryptic , but the "result" is still wrong =... (3 Replies)
Discussion started by: anne
3 Replies

2. Shell Programming and Scripting

How to Force command substitution evaluation in bash?

OK, I'm striving to abide by all the rules this time. Here is a fragment of my windows10/cygwin64/bash script: export BUPLOG=$(BackupRecords --log "$src") robocopy $(BackupRecords -mrbd "$src" --path "$src") $(BackupRecords --appSwitches "$src") "$src" "$dst" $(BackupRecords --fileSwitches... (0 Replies)
Discussion started by: siegfried
0 Replies

3. Shell Programming and Scripting

Bash regex evaluation not workin

I'm building a script that may received start and end date as parameters. I whant to make it as flexible as possible so I'm accepting epoch and date in a way that "date --date=" command may accept. In order to know if parameter provided is an epoc or a "date --date=" string I evaluate if the value... (2 Replies)
Discussion started by: lramirev
2 Replies

4. Shell Programming and Scripting

bash, command line substitution

I have one script calling another with a set of strings that includes white space. Script A calls Script B with these input strings: one two "th ree" Script B pulls apart the arguments correctly: arg0 = one, arg1 = two, arg2 = "th ree" if I call it from within Script A like so:... (10 Replies)
Discussion started by: skippyV
10 Replies

5. UNIX for Dummies Questions & Answers

cp command evaluation

Hi all! I'm writting one script to copy a file in various folders, but there are 2 things to validate. First that the folder where i'll be cpying exists, and second that i have permissions to copy the file in it. so far i have found the way to validate the folder exists, but when trying to... (6 Replies)
Discussion started by: feliperivera
6 Replies

6. Shell Programming and Scripting

Correct bash substitution

Hello! I'm writing a shell script using #!/bin/bash instead of #!/bin/sh because of the substitution: ${!variable}, which won't work with sh. My main problem is the following (just a summarized example, the script is much more complex): # sourced from a configuration file, we have a lot of... (6 Replies)
Discussion started by: teresaejunior
6 Replies

7. Shell Programming and Scripting

[bash] command line substitution with environmental variables

Hi, I'm using an array that contains compiler FLAGS that need to be executed either before ./configure or after the main 'make' command. example of array containing compiler flags. ------------------------------------------------- FLAGS="CFLAGS=\"-arch x86_64 -g -Os -pipe... (7 Replies)
Discussion started by: ASGR
7 Replies

8. Shell Programming and Scripting

/bin/bash - variable substitution.

Is it possible with a bash variable to perform multiple substitution strings to one variable? I have this variable: echo $clock TIMEZONE="US/Central" What I would like to do with bash only it pull out just the "US" part of the variable.. which could be any number of countries. this is... (6 Replies)
Discussion started by: trey85stang
6 Replies

9. Shell Programming and Scripting

How do I perform double substitution in bash?

#!/bin/bash #set -x MAX=255 FILE=$1.dns_list #declare -a d_arr if then echo "Usage: `basename $0` network" echo " e.g.`basename $0` 1.1.1" exit fi echo "Remove file $FILE..." rm $FILE for (( i = 1; i < $MAX; i++ )) do PARSE=$(host $1.${i}) ... (3 Replies)
Discussion started by: flee
3 Replies
Login or Register to Ask a Question