我想实现一个bash函数,test是第一个参数实际上是一个变量,在某处定义.
例如,在我的.bashrc:
customPrompt='yes';
syntaxOn='no';
[...]
function my_func {
[...]
# I want to test if the string $1 is the name of a variable defined up above
# so something like:
if [[ $$1 == 'yes' ]];then
echo "$1 is set to yes";
else
echo "$1 is not set or != to yes";
fi
# but of course $$1 doesn't work
}
Run Code Online (Sandbox Code Playgroud)
需要输出:
$ my_func customPrompt
> customPrompt is set to yes
$ my_func syntaxOn
> syntaxOn is …Run Code Online (Sandbox Code Playgroud) 只是关于优化的问题,在:
<a href="#" onClick="javascript:window.open('myUrl.com');">link-1</a>
Run Code Online (Sandbox Code Playgroud)
并且:
<a href="javascript:window.open('myUrlBis.com');">link-2</a>
Run Code Online (Sandbox Code Playgroud)
这个比那个好吗 ?还是更兼容?谢谢.
我想重置shell,因为我从头开始注册/登录,重新加载别名,函数.
但是不要谈论source ~/.bashrc也不. ~/.bashrc!
为什么?因为source或.只是丰富了当前的shell,使用了新的函数,别名等等.
仅供参考,你可以把这个功能放在你的bashrc中:
function foo {
echo "foo";
}
Run Code Online (Sandbox Code Playgroud)
然后做source ~/.bashrc或. ~/.bashrc.是的,foo正在工作.那么现在,edityour .bashrc,并更换FOO的酒吧,有:
function bar {
echo "bar";
}
Run Code Online (Sandbox Code Playgroud)
您现在可以键入foo,并看到函数foo仍在工作,尽管它在.bashrc文件中不再存在.这就是我想表达的观点.
我exec bash;试过了,但它没有加载.bashrc文件.并且exec bash;source ~/.bashrc;显然不起作用,因为exec杀死当前进程(source从未被调用).
所以我有这个DOM代码:
<div id="foobar">
H<br />
e<br />
l<br />
l<br />
o
</div>
<script>
var foobarElement = document.getElementById('foobar');
foobarElement.style.backgroundImage = '';
foobarElement.style.background = '';
foobarElement.style.backgroundUrl = '';
foobarElement.style.backgroundColor = 'green';
</script>
Run Code Online (Sandbox Code Playgroud)
在div上使用CSS属性:
#foobar {
background: rgba(0, 0, 0, 0) url("https://www.google.fr/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png") repeat scroll 0 0;
}
Run Code Online (Sandbox Code Playgroud)
(丑陋)小提琴
正如您所看到的,我正在尝试完全删除background属性CSS(在我的示例中为Google徽标),而不使用Jquery.
在我的例子中,我无法编辑CSS,也没有编写DOM之前的东西<div id="foobar">.
注意:如果在CSS中使用background-image相同的url而不是使用CSS,则一切正常background
任何的想法 ?
资源:
sort工作怎么样?我有这个文件:
/test# cat foobar
html/lib/ORM/aaa.php
html/lib/ORMBase/ormbase_aaa.php
html/lib/ORM/zzz.php
html/lib/ORMBase/ormbase_zzz.php
Run Code Online (Sandbox Code Playgroud)
这是输出sort:
/test# cat foobar | sort
html/lib/ORM/aaa.php
html/lib/ORMBase/ormbase_aaa.php
html/lib/ORMBase/ormbase_zzz.php
html/lib/ORM/zzz.php
Run Code Online (Sandbox Code Playgroud)
我尝试了很多的选项:-f,-i,-t/...,我不明白这一点.我想理解为什么排序认为这是排序的.
注意:它适用于其他样本:
/test# cat foobar2
a/a/a
a/ab/a
a/ab/b
a/a/ab
a/abc/a
/test# cat foobar2 | sort
a/a/a
a/a/ab
a/ab/a
a/ab/b
a/abc/a
Run Code Online (Sandbox Code Playgroud) 我对如何使用 ansible 管理多个环境(生产/开发)感到非常困惑。我也在使用molecule进行本地测试。
这是我现在的项目布局。
|----inventories/
| |
| |--dev/
| | |
| | |--group_vars/...
| | |
| | |--host_vars/...
| |
| |--prod/
| |
| |--group_vars/...
| |
| |--host_vars/
| |
| |--my_playbook_hostname_vars.yml
|
|----roles/...
|
|----hosts.yml
|
|----my_playbook.yml
|
Run Code Online (Sandbox Code Playgroud)
这是根据文档的目录结构
现在我有了我的分子文件,我可以像这样链接开发目录
# molecule.yml
provisioner:
name: ansible
inventory:
links:
group_vars: ../../../../inventories/dev/group_vars/
host_vars: ../../../../inventories/dev/host_vars/
Run Code Online (Sandbox Code Playgroud)
因此,Molecule 可以很好地使用 vagrant 驱动程序进行本地测试,例如,我还可以将其设置为使用 EC2 驱动程序在云中进行测试。到目前为止,一切都很好。
但如何启动 my_playbook.yml 呢?当我使用ansible-playbook my_playbook.ymlthen 时,它不知道在哪里寻找变量,因为有两个环境。我怎样才能告诉 Ansible 在 inventory/prod/group_vars 和 inventory/prod/host_vars 下查找,然后通过主机和组名称进一步解析,就像在hosts.yml中定义的那样,而不影响我的分子设置?
当我刚刚在根目录中设置 group_vars/ & …
我有这个数组 - 它是一个多维数组,我不知道0索引:
Array
(
[0] => Array
(
[foo] => 1111
[bar] => example
)
)
Run Code Online (Sandbox Code Playgroud)
我需要在一行中使用本机php函数来获取密钥的值bar.我试着用很多的组合current,key,array_keys,等等.随着current($array)我:
Array
(
[foo] => 1111
[bar] => example
)
Run Code Online (Sandbox Code Playgroud)
我发现array_keys,允许我使用第二个参数指定要查找的值.但我不知道价值,只知道关键,并array_values没有提出第二个论点来找到(:o).
我现在在这里:current(array_keys(array_flip(current($b))), 'bar')没有工作.但
$c = array_flip(current($b));
print_r(current(array_keys($c, 'bar')));
Run Code Online (Sandbox Code Playgroud)
工作 - 我得到"例子".(顺便说一句,为什么这两条线路正在工作而不是前一条线路?).
而且我知道,这用起来很难看array_flip,但我不知道怎么办.任何的想法 ?谢谢.
bash ×3
javascript ×2
optimization ×2
unix ×2
ansible ×1
dom ×1
exec ×1
html ×1
if-statement ×1
laravel-8 ×1
php ×1
shell ×1
sorting ×1
variables ×1