首页 > 解决方案 > how I call the source ~./.bash_profile script from another shell script?

问题描述

I what to call source.sh script in another script main.sh script source.sh has following

   #!/bin/sh
    ~/.bash_profile



 #main.sh has following 
    tar -xzvf /home/admin/perf/jdk-8u201-linux-x64.tar.gz >> /home/admin/perf/output.txt &&
    sleep 1
    echo "Export Path for Environmental Variable"
    sudo echo "export PATH=/home/admin/perf/jdk1.8.0_201/jre/bin/:/home/admin/perf/jdk1.8.0_201/bin/:$PATH" >> /home/admin/.bash_profile
    sudo echo "export JAVA_HOME=:/home/admin/perf/jdk1.8.0_201" >> /home/admin/.bash_profile
    sleep 1
    echo "Persisting JDK PATH to .bash_profile"
    source /home/admin/perf/./source.sh

when I execute ./main.sh
    
#Result is ./source.sh script is not setting the export path in the same shell. 

标签: bashpath

解决方案


#!/usr/bin/bash用于重生 shell,意思是 bash,在大多数系统上,这是 bash 脚本的第一行,您的行#!/bin/sh可能不正确。但我可能错了。

要调用 bash_profile,您可以输入source ~/.bash_profile,但我会查看第一行,即解释器。


推荐阅读