日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > linux >内容正文

linux

linux bash函数里面调用命令行,Linux-在gnome-terminal -x中运行bash函数

發(fā)布時(shí)間:2023/12/20 linux 63 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux bash函数里面调用命令行,Linux-在gnome-terminal -x中运行bash函数 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

您可以將其與export -f一起使用,就像@kojiro的上面的注釋中指出的那樣.

# Define function.

my_func() {

// Do cool stuff

}

# Export it, so that all child `bash` processes see it.

export -f my_func

# Invoke gnome-terminal with `bash -c` and the function name, *plus*

# another bash instance to keep the window open.

# NOTE: This is required, because `-c` invariably exits after

# running the specified command.

# CAVEAT: The bash instance that stays open will be a *child* process of the

# one that executed the function - and will thus not have access to any

# non-exported definitions from it.

gnome-terminal -x bash -c 'my_func; bash'

借助一些技巧,您可以不用export -f,而可以假設(shè)運(yùn)行該函數(shù)后保持打開狀態(tài)的bash實(shí)例本身不需要繼承my_func.

聲明-f返回my_func的定義(源代碼),因此只需在新的bash實(shí)例中重新定義它即可:

gnome-terminal -x bash -c "$(declare -f my_func); my_func; bash"

再一次,如果需要,您甚至可以在其中擠壓export -f命令:

gnome-terminal -x bash -c "$(declare -f my_func);

export -f my_func; my_func; bash"

總結(jié)

以上是生活随笔為你收集整理的linux bash函数里面调用命令行,Linux-在gnome-terminal -x中运行bash函数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。