Skip to main content
Became Hot Network Question
added 391 characters in body
Source Link

Trying to test something and not quite nailing it either way I've tried, so not sure if I'm being silly or not.

Essentially I wantneed to parse a string to ipa-getcertgetcert's post-save argument which should include the date, butyear of the datecertificate renewal. This means the script will run once to request the certificate and then the current year can be some future dateused (simple). But then when ipa-getcert renews a certificate it will run a command with arguments post-save, and it's at this time that depends on an external systemthe year of the renewal must be used. So I'd likeThe whole string to do thisget a certificate issued including the post-save option [-C] is:

RENEW_CMD="$INST_CERTsudo ipa-getcert request -N $CERT_CN -K HTTP/$CERT_CN -k /etc/ssl/private/${CERT_CN}.key -f /etc/ssl/certs/${CERT_CN}.crt \
-D $CERT_CN -C "$INST_CERT -n ${CERT_NAME}_"'$(date +"%Y")'" $INST_OPTS $PAN_MGMT"

Attempting to test this I know the single quotes ensure that the current date isn't parsed as text intotried the variablefollowing, but I want to ensure that it is expanded later on. So I did a simple test and the date is never expanded... Is there a better way to test this, apart from using ipa-getcert to test?

$ txt="The year is: "
$ echo $txt$(date +"%Y")
The year is: 2023
$ echo $txt'$(date +"%Y")'
The year is: $(date +"%Y")
$ echo $(echo $txt'$(date +"%Y")')
The year is: $(date +"%Y")

But echoing the string does, so the single quotes seem to remain even when not printed on screen.

$ echo The year is: $(date +"%Y")
The year is: 2023

Undoubtedly I'm missing something trivial here.

[EDIT:] But then the following works fine, so maybe I'm just paranoid?

$ mkdir $(date +"%Y")
$ test2="ll "'$(date +"%Y")'
$ echo $test2
ll $(date +"%Y")
$ eval $test2
total 8
drwxrwxr-x  2 user group 4096 Apr 24 20:01 ./
drwxr-xr-x 13 user group 4096 Apr 24 20:01 ../

Trying to test something and not quite nailing it either way I've tried, so not sure if I'm being silly or not.

Essentially I want to parse a string to ipa-getcert which should include the date, but the date will be some future date that depends on an external system. So I'd like to do this:

RENEW_CMD="$INST_CERT -n ${CERT_NAME}_"'$(date +"%Y")'" $INST_OPTS $PAN_MGMT"

I know the single quotes ensure that the current date isn't parsed as text into the variable, but I want to ensure that it is expanded later on. So I did a simple test and the date is never expanded...

$ txt="The year is: "
$ echo $txt$(date +"%Y")
The year is: 2023
$ echo $txt'$(date +"%Y")'
The year is: $(date +"%Y")
$ echo $(echo $txt'$(date +"%Y")')
The year is: $(date +"%Y")

But echoing the string does, so the single quotes seem to remain even when not printed on screen.

$ echo The year is: $(date +"%Y")
The year is: 2023

Undoubtedly I'm missing something trivial here.

[EDIT:] But then the following works fine, so maybe I'm just paranoid?

$ mkdir $(date +"%Y")
$ test2="ll "'$(date +"%Y")'
$ echo $test2
ll $(date +"%Y")
$ eval $test2
total 8
drwxrwxr-x  2 user group 4096 Apr 24 20:01 ./
drwxr-xr-x 13 user group 4096 Apr 24 20:01 ../

Trying to test something and not quite nailing it either way I've tried, so not sure if I'm being silly or not.

Essentially I need to parse a string to ipa-getcert's post-save argument which should include the year of the certificate renewal. This means the script will run once to request the certificate and then the current year can be used (simple). But then when ipa-getcert renews a certificate it will run a command with arguments post-save, and it's at this time that the year of the renewal must be used. The whole string to get a certificate issued including the post-save option [-C] is:

sudo ipa-getcert request -N $CERT_CN -K HTTP/$CERT_CN -k /etc/ssl/private/${CERT_CN}.key -f /etc/ssl/certs/${CERT_CN}.crt \
-D $CERT_CN -C "$INST_CERT -n ${CERT_NAME}_"'$(date +"%Y")'" $INST_OPTS $PAN_MGMT"

Attempting to test this I tried the following, but the date is never expanded. Is there a better way to test this, apart from using ipa-getcert to test?

$ txt="The year is: "
$ echo $txt$(date +"%Y")
The year is: 2023
$ echo $txt'$(date +"%Y")'
The year is: $(date +"%Y")
$ echo $(echo $txt'$(date +"%Y")')
The year is: $(date +"%Y")

But echoing the string does, so the single quotes seem to remain even when not printed on screen.

$ echo The year is: $(date +"%Y")
The year is: 2023

Undoubtedly I'm missing something trivial here.

[EDIT:] But then the following works fine, so maybe I'm just paranoid?

$ mkdir $(date +"%Y")
$ test2="ll "'$(date +"%Y")'
$ echo $test2
ll $(date +"%Y")
$ eval $test2
total 8
drwxrwxr-x  2 user group 4096 Apr 24 20:01 ./
drwxr-xr-x 13 user group 4096 Apr 24 20:01 ../
added 309 characters in body
Source Link

Trying to test something and not quite nailing it either way I've tried, so not sure if I'm being silly or not.

Essentially I want to parse a string to ipa-getcert which should include the date, but the date will be some future date that depends on an external system. So I'd like to do this:

RENEW_CMD="$INST_CERT -n ${CERT_NAME}_"'$(date +"%Y")'" $INST_OPTS $PAN_MGMT"

I know the single quotes ensure that the current date isn't parsed as text into the variable, but I want to ensure that it is expanded later on. So I did a simple test and the date is never expanded...

$ txt="The year is: "
$ echo $txt$(date +"%Y")
The year is: 2023
$ echo $txt'$(date +"%Y")'
The year is: $(date +"%Y")
$ echo $(echo $txt'$(date +"%Y")')
The year is: $(date +"%Y")

But echoing the string does, so the single quotes seem to remain even when not printed on screen.

$ echo The year is: $(date +"%Y")
The year is: 2023

Undoubtedly I'm missing something trivial herhere.

[EDIT:] But then the following works fine, so maybe I'm just paranoid?

$ mkdir $(date +"%Y")
$ test2="ll "'$(date +"%Y")'
$ echo $test2
ll $(date +"%Y")
$ eval $test2
total 8
drwxrwxr-x  2 user group 4096 Apr 24 20:01 ./
drwxr-xr-x 13 user group 4096 Apr 24 20:01 ../

Trying to test something and not quite nailing it either way I've tried, so not sure if I'm being silly or not.

Essentially I want to parse a string to ipa-getcert which should include the date, but the date will be some future date that depends on an external system. So I'd like to do this:

RENEW_CMD="$INST_CERT -n ${CERT_NAME}_"'$(date +"%Y")'" $INST_OPTS $PAN_MGMT"

I know the single quotes ensure that the current date isn't parsed as text into the variable, but I want to ensure that it is expanded later on. So I did a simple test and the date is never expanded...

$ txt="The year is: "
$ echo $txt$(date +"%Y")
The year is: 2023
$ echo $txt'$(date +"%Y")'
The year is: $(date +"%Y")
$ echo $(echo $txt'$(date +"%Y")')
The year is: $(date +"%Y")

But echoing the string does, so the single quotes seem to remain even when not printed on screen.

$ echo The year is: $(date +"%Y")
The year is: 2023

Undoubtedly I'm missing something trivial her

Trying to test something and not quite nailing it either way I've tried, so not sure if I'm being silly or not.

Essentially I want to parse a string to ipa-getcert which should include the date, but the date will be some future date that depends on an external system. So I'd like to do this:

RENEW_CMD="$INST_CERT -n ${CERT_NAME}_"'$(date +"%Y")'" $INST_OPTS $PAN_MGMT"

I know the single quotes ensure that the current date isn't parsed as text into the variable, but I want to ensure that it is expanded later on. So I did a simple test and the date is never expanded...

$ txt="The year is: "
$ echo $txt$(date +"%Y")
The year is: 2023
$ echo $txt'$(date +"%Y")'
The year is: $(date +"%Y")
$ echo $(echo $txt'$(date +"%Y")')
The year is: $(date +"%Y")

But echoing the string does, so the single quotes seem to remain even when not printed on screen.

$ echo The year is: $(date +"%Y")
The year is: 2023

Undoubtedly I'm missing something trivial here.

[EDIT:] But then the following works fine, so maybe I'm just paranoid?

$ mkdir $(date +"%Y")
$ test2="ll "'$(date +"%Y")'
$ echo $test2
ll $(date +"%Y")
$ eval $test2
total 8
drwxrwxr-x  2 user group 4096 Apr 24 20:01 ./
drwxr-xr-x 13 user group 4096 Apr 24 20:01 ../
Source Link

Parse command with expanded variables

Trying to test something and not quite nailing it either way I've tried, so not sure if I'm being silly or not.

Essentially I want to parse a string to ipa-getcert which should include the date, but the date will be some future date that depends on an external system. So I'd like to do this:

RENEW_CMD="$INST_CERT -n ${CERT_NAME}_"'$(date +"%Y")'" $INST_OPTS $PAN_MGMT"

I know the single quotes ensure that the current date isn't parsed as text into the variable, but I want to ensure that it is expanded later on. So I did a simple test and the date is never expanded...

$ txt="The year is: "
$ echo $txt$(date +"%Y")
The year is: 2023
$ echo $txt'$(date +"%Y")'
The year is: $(date +"%Y")
$ echo $(echo $txt'$(date +"%Y")')
The year is: $(date +"%Y")

But echoing the string does, so the single quotes seem to remain even when not printed on screen.

$ echo The year is: $(date +"%Y")
The year is: 2023

Undoubtedly I'm missing something trivial her