Source functions from variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Source functions from variable
# 1  
Old 07-25-2017
Source functions from variable

so i found a way to do this.

Code:
#!/bin/bash
MYF=$(/home/jason/myfunctions)
source <(printf '%s\n' "${MYF}")
echo "${var1}"

/home/jason/myfunctions is a script that outputs information..i.e. functions...etc that needs to be sourced. I have no control over /home/jason/myfunctions. i can only run it.

the above works for me. as im able to source the output of the myfunctions script. however, the above solution is not portable. it only seems to work on newer versions of bash.

can anyone look at the above solution and come up with a modified version of it that will work everywhere on all unix systems?
# 2  
Old 07-25-2017
What keeps you from sourcing myfunctions immediately?
# 3  
Old 07-25-2017
Quote:
Originally Posted by RudiC
What keeps you from sourcing myfunctions immediately?
Nothing really. But that still isn't portable Smilie
# 4  
Old 07-25-2017
Are you building rube goldbergian code mutators again?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Source functions from variable

I have a functions file containing functions: file.functions: myTest () { echo "MYPWD=$(echo $(pwd))" echo "MYLOGNAME=${LOGNAME}" } myCar () { echo "MYDATE=$(date)" echo "MYUPTIME=$(uptime)" } i know i can source this file in another script using something similar to this: source... (8 Replies)
Discussion started by: SkySmart
8 Replies

2. Shell Programming and Scripting

Local variable in functions (gawk)

Hi Everybody :) I need your help, because i know a local variable in a function for example k, it is different of other variable(with the same name k) this a global variable. Is that right? dgawk> run Starting program: 3238860128818202 3 4 7 11 12 13 17 22 23 32 35 37 41 48 49 55 63 ... (5 Replies)
Discussion started by: solaris21
5 Replies

3. Shell Programming and Scripting

Need help on Assigning a Array variable from Background Functions

I have a question on how can I assign a output of a function to a variable which is executed in background. Here is my example $ cat sample_program.sh #!/bin/ksh exec_func () { sleep 1 v=`expr $1 + 100` print $v } export OUT_ARR date for i in 1 2 do OUT_ARR=`exec_func $i` &... (1 Reply)
Discussion started by: mohan_kumarcs
1 Replies

4. Shell Programming and Scripting

Share variable between functions

Hi, gtkdialog gui seperate buttons use seperate functions in their GUI. A variable (newFolderName) is being set in one function (funcA) and it needs to be called in another function (funcB). I thought using global variable (like in python) concept should work however it does not. ... (4 Replies)
Discussion started by: singhai.nish
4 Replies

5. UNIX for Dummies Questions & Answers

Overwrite a Source Script Variable Value

Hello All, How do i overwrite a sourced script variable value. Sourced Script: GEN_PARAM_LIST4=""$LOG_DIR"/dwh_GenerateXMLFile.lst" GEN_PARAM_LIST4_v2=""$LOG_DIR"/dwh_GenerateXMLFile.v2.lst" I am using below statement for replacing. Script2: &&... (1 Reply)
Discussion started by: Ariean
1 Replies

6. Shell Programming and Scripting

How to execute functions or initiate functions as command line parameters for below requirement?

I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line if then... (8 Replies)
Discussion started by: saku
8 Replies

7. Shell Programming and Scripting

Source environment variable in script

Hi, I construct a bash script to finish some tasks. One of the task is to set up some environment variables. There is already one script file to complete the environment variables setting work. I am not able to know the detail of how to set these variables. So, I may just need to call this... (4 Replies)
Discussion started by: gofortime
4 Replies

8. UNIX for Dummies Questions & Answers

== vs -eq and functions

Hey I have a question.... what is the difference between using == vs -eq when testing in WHILE loops. I use the following test that only worked with == signs.... if why do i need == and not -eq? 2. I need to re-use some code in a couple places in this script. is functions my best... (5 Replies)
Discussion started by: danieldcc
5 Replies

9. Shell Programming and Scripting

Use of functions

Hi my shell is tcsh can I have functions in my shell scripting? Is the below shell script correct. Can I have two functions and call one of them as required. ---------- echo "functions" f1 f1 () { echo "hello" } f2 () (1 Reply)
Discussion started by: amitrajvarma
1 Replies
Login or Register to Ask a Question