python - 将变量作为参数传递

标签 python linux shell

我有一个 python 脚本 sms.py,它需要两个参数:

1) 手机号码

2) 一个随机数

随机数由以下方式生成:

myrandnumber=<code>expr '(' $RANDOM '*' 30 / 32767 ')' + 1</code>

我的 sh 脚本如下所示:

myrandnumber=`expr '(' $RANDOM '*' 30  / 32767 ')' + 1`

cd /home/janu/programs/

output_filename=output/output-`date +%Y%m%d-%H.%M.%S`.txt
python sms.py -mob 917204785003 --key $myrandnumber > $output_filename

我无法获取“$myrandnumber”值。

最佳答案

如果您制作了 sms.py 脚本,则最好在 python 代码中使用随机库:

   import random
   key = random.randint(1,3000) # 1 to 3000 inclusive

关于python - 将变量作为参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12068693/

相关文章:

c - 使用全局变量的线程问题

shell - jq - 不能用字符串索引字符串

python - 我如何打印列表中的项目,直到它们达到一定数量的行

linux - "Pentium4 and above"处理器的 gcc 的最佳 march 和 mtune 选项是什么

python - isinstance 在 python 中如何为子类工作?

linux - 查找 Ubuntu 驱动程序的源代码

linux - 在 bash 脚本上做完整的工作流

python - impala shell,带大写字母的 shell 命令

python - 重复调用函数的函数?

python - 如何从QThread调用widget的方法