I stumbled across this odd behavior by accident while working on a project. Here is the demo code that will reproduce the same issue -
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
parser = argparse.ArgumentParser(description='Random observations')
parser.add_argument('-g', '--get', help='Get n of something')
parser.add_argument('-c','--create', help='Create something')
args = vars(parser.parse_args())
if args['get']:
print(f"Retrieved {args['get']} resources...")
if args['create']:
print(f"Created resource..{args['create']}")
I made the script executable just for brevity using chmod +x filename
Now, this is where it gets wierd. If i run the script like this -
$ ./so -c "Calling `./so -g 5`"
I get the output as -
Created resource..Calling Retrieved 5 resources...
Why is the command in string getting executed, shouldn't it just go in as a string and come out as a string ?
I did a few more experiments and here are my findings:
Command -
$ ./so -c """Calling `./so -g 5`"""
Output
Created resource..Calling Retrieved 5 resources...
Command -
$./so -c '''Calling `./so -g 5`'''
Output -
Created resource..Calling `./so -g 5`
Why is the last one working as expected and not the others?
P.S I do not know the necessary tags for this question, please feel free to edit it.