I am executing exec_command in Python. The command is : find -path . -mmin -$time -print. And I am assigning time=100. But while executing the command, exec_command does not picks up the variable value. or even I do exec_command('echo $time'). It does not picks up the value.
1 Answer
Python and the shell have separate variables. Setting time in your Python script does not magically create a variable called $time that you can then use in shell commands. It especially does not magically create a shell variable on some other computer which is what it appears you're trying to do.
Instead, put the Python value into the string you're passing. For example:
command = 'find -path . -mmin -%d -print' % time
print(command) # shows the exact command that will be executed
exec_command(command)
Be careful with this. It's very easy to create security holes if you don't know what you're doing, especially when you take strings from user input or other data sources you don't control. In this example I've used %d to substitute the value into the command, and this will keep anything but a number from being used, which should be safe.