logo
down
shadow

Call function from another shell script


Call function from another shell script

By : kiko
Date : November 19 2020, 03:59 PM
seems to work fine I have write a script, and I like to now to make it better readable, by moving parts of my main script in other files, but unfortunately I cannot. , You have to source it, with . or source:
code :
~$ cat >main.sh
#!/bin/bash
. ./utils.sh #or source ./utils.sh
sayHello
~$ ./main.sh
Hello World


Share : facebook icon twitter icon
Can I call a function of a shell script from another shell script?

Can I call a function of a shell script from another shell script?


By : Mansi Malhotra
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I have 2 shell scripts. , Refactor your second.sh script like this:
code :
function func1 {
   fun=$1
   book=$2
   printf "fun=%s,book=%s\n" "${fun}" "${book}"
}

function func2 {
   fun2=$1
   book2=$2
   printf "fun2=%s,book2=%s\n" "${fun2}" "${book2}"
}
source ./second.sh
func1 love horror
func2 ball mystery
fun=love,book=horror
fun2=ball,book2=mystery
call main script function in script files called inside in shell script

call main script function in script files called inside in shell script


By : Sharmin Sultana
Date : March 29 2020, 07:55 AM
seems to work fine This is not portable, but in bash you can simply export the function definition:
code :
export -f log
home/script/loadFile.sh && home/script/processData.sh
Call function in shell script

Call function in shell script


By : Aziz Hasanov
Date : March 29 2020, 07:55 AM
will help you You just need to pass the arguments ($@) to the function sum() that you pass to your script:
code :
#!/bin/bash

sums() {
    sum=0
    for i in $@; do sum=$((sum+i)); done
    echo $sum
    exit 0
}

sums "$@" # Note this line
How to call c function from shell script?

How to call c function from shell script?


By : Lee S Jackson
Date : March 29 2020, 07:55 AM
it helps some times Unfortunately you would need to compile the C code into an executable file, possibly with a command line interface if you need to parse arguments. From there you can call your executable in the shell script.
How to call a function (defined in shell script) in a Perl script

How to call a function (defined in shell script) in a Perl script


By : J. Jasper
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , To invoke a shell function, the shell needs to know its definition. One way to achieve that is to have the shell first source the file which defines the function. And then, without exiting the shell, call the function. From a Perl script, that would be for example:
code :
system 'bash', '-c', 'source shell_script.sh; func_1';
Related Posts Related Posts :
  • how to replace a string at a specific position in a csv file using bash
  • how to delete duplicate lines in a text file in unix bash?
  • Compare a variables in bash
  • How do I use sed on a string?
  • Using bash variables for range in sed
  • convert a DURATION HH:MM:SS to seconds in bash
  • Shell make system paths click-able when printed out by my shell script
  • I want to use parallel-ssh to run a bash script on multiple servers, but it simple prints the echo statements
  • AWK between 2 patterns - first occurence
  • Nginx on docker - daemonize and attach to bash
  • Delete or Replace nth line in a file after a pattern match using shell scripts
  • Actual return code for SCP
  • How to exit a bash function that expects a return
  • Bash script to split file into two files while changing output file during processing
  • Pass command line arguments via sbatch
  • variable substitution (what do you call/name this method)?
  • How to Grep and Replace With Exclusions
  • shell command to remove characters after a special character in bash/shell
  • How do I run a script for 1st working day of every month in cron?
  • Bash Unexpected End of File Error After Installing RVM
  • Nested Loop with increment on inner loop?
  • video orientation detection in bash
  • Interrupt sleep in bash with a signal trap
  • Want file rename script to add number at end with fixed length
  • What's the DRYest way to replace a file with a symlink in bash
  • How to run Bitcoin's autogen.sh file?
  • Renaming files in folder and subfolders using a list- Bash Script/Unix
  • Bash command to compare more than two files
  • If It is a directory append text
  • What's wrong with my WHILE-DO loop, or why my script can't find the file I'm giving it on a plate?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org