办法
编写程序运行shell脚本,将脚本 copy 到 /etc/profile.d 目录。机器开机启动时会自动执行 /etc/profile.d 目录下的所有shell脚本。
Demo
~/ 目录下创建test.cpp测试程序。
//code needs to run
#include<stream>
using namespace std;
int main()
{
cout << "Test For Setting Start!!!" << endl;
return 0;
}
将test.cpp编译为可执行程序。
g++ test.cpp -o test
~/ 目录下创建test.sh测试shell脚本。
#!/bin/sh
gnome-terminal -x bash -c 'cd ~/;./test; exec bash'
最后为test.sh添加权限,并copy到 /etc/profile.d 目录,重启机器观察现象。