在bash中使用前导数字设置环境变量 [英] Setting environment variable with leading digit in bash

查看:101
本文介绍了在bash中使用前导数字设置环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在bash中设置一个名为"64bit"(即带有前导数字)的环境变量.但是,bash变量名称不允许带有前导数字的变量.我知道一种在调用bash时进行设置的方法:

I need to set an environment variable called "64bit" (i.e. with a leading digit) in bash. However, bash variable names disallow a variable with a leading digit. I know a way to set it when invoking bash:

env 64bit=1 /usr/bin/bash

但是,我正在寻找一种方法来更改当前正在运行的shell,即不通过启动新的shell.我也知道csh允许变量以数字开头,但是我需要使用bash.

However, I'm looking for a way to change it in the currently running shell i.e. not by starting a new shell. I also know that csh allows variables to start with a digit, but I need to use bash.

有什么办法可以做到这一点?

Is there any way to achieve this?

推荐答案

您还可以绕过bash解释器并直接使用bash内部函数定义变量:

You can also bypass the bash interpreter and define the variable directly with the bash internal functions:

$ gdb --batch-silent -ex "attach $$"                              \
    -ex 'set bind_variable("64bit", "1", 0)'                      \
    -ex 'set *(int*)(find_variable("64bit")+sizeof(char*)*5) = 1' \
    -ex 'set array_needs_making = 1'

$ env | grep 64
64bit=1

这篇关于在bash中使用前导数字设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆