1.编写启动脚本start.sh
#!/bin/sh
cd /home/Software/
./test1 &
其中:
/home/Software:为编译好的可执行文件的路径
test1:可执行程序
&:表示可以后台运行
2.将此脚本加到系统启动文件 ~/.porfile中
编写~/.proflie文件 ,编写完成后:
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.
# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
bash /home/Software/start.sh &
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
其中:
/home/Software:为文件start.sh的路径;
注意事项:
1. "&"不能省略,否则开机切换不了界面,系统只运行start.sh中的程序
2. 最好在重启之前验证一下脚本是否有效,验证方法是打开终端输入:
bash /home/Software/start.sh
看是表现是否符合预期。
3.脚本中出现的路径最好用绝对路径。