Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [bash-functions]

The tag has no usage guidance.

4
votes
6answers
2k views

How to export all Bash functions in a file in one line?

In Ubuntu 16.04 I have a Bash file containing a few different functions for automating various common tasks on my system. I have sourced that file in bashrc so I could comfortably call each function ...
0
votes
1answer
57 views

Bash function call from script file fails, while call from terminal succeeds

In Ubuntu 16.04 with Bash I created a file $HOME/ulcwe/software_internal.sh that contains a function rse() without a call. The file is sourced in ~/.bashrc (which was sourced by itself) and I can can ...
1
vote
1answer
137 views

Bash function that creates an alias gets called endlessly

I ran the following Bash function that adds a string with expanded variables, into the end of my bashrc: alias() { echo "alias $repo=\"$HOME\"/$repo/$repo.sh" >> "$HOME"/.bashrc source "...
0
votes
0answers
24 views

Making a simple script for counting which members of a set have appeared, and outputting probability of appearance of the remaining members

I am creating a simple bash script, but am relatively new to it. Hear me out and the easy (I hope) question will follow. i need to make a script that will take input from the keyboard to know which ...
1
vote
1answer
353 views

How can I convert a folder of audio files into a single file (iterate over many folders)?

I have a couple of radio plays of various series. Some are already single-track, some are multi-track. I want all to be single-track. I don't mind re-encoding; in fact I want to transfer them to my ...
2
votes
4answers
181 views

Run a specific function from a file that contains 2 or more functions, in a detached tmux session

I use Ubuntu 16.04 with Bash and I have a file that contains many different functions. In between these functions, there is this one: tdm() { chmod -R a-x,a=rX,u+w "$drt"/phpmyadmin/ sleep 2h ...
0
votes
2answers
71 views

Bash: A function-like structure that doesn't require a call? [closed]

I desire some kind of data structure that looks similarly to a Bash function but isn't a function. A named structure to organize commands by context, that should also allow leading tabs. This is nice ...
1
vote
2answers
81 views

How to make a customized function in bash file

I am looking for a way to create a customized function in one of the setting files, so that when I open up a new session, the same customized function can be evaluated (or sourced), and I can use the ...
1
vote
0answers
71 views

Would a 'function_not_found_handle ()' loadable bash builtin be possible?

I wrote a function to handle unknown commands in bash via command_not_found_handle (). My intention is to source scripts on demand and access its functions inside the handler. But unfortunately the ...
0
votes
2answers
7k views

How to read the output of a previous command in a shell script? [duplicate]

I executed a command in a shell script and the command ends with "completed successfully" or "completed unsuccessfully". How can I read that in the script and use it for if and else conditions?
1
vote
1answer
1k views

Start function in background and save PID

I have a script containing two functions. one function starts the other as a background process and returns that processes UID. This works well, as long as I don't want to put the PID into a dedicated ...
1
vote
1answer
571 views

BASH: declare a local function in remote host with interactive shell

glad to write it for you here. I've done a lot of searching about that and haven't found a solution. What I want to do is relatively simple. There is a caveat local bash function in my workstation ...
0
votes
1answer
369 views

How to pass an argument containing double quote to a shell script function?

I have in pull_news.sh (variable declarations omitted): dump_table () { mysqldump --user=${REMOTE_USERNAME} --password=${REMOTE_PASSWORDS} --host=${REMOTE_HOST} --port=${REMOTE_PORT} --single-...
0
votes
2answers
78 views

Find location of shell / bash function on disk [duplicate]

If I have a function like so: #!/usr/bin/env bash function foo { } and the above function is in .bash_profile, or somewhere. If I use which foo it won't give me the location of this ...
1
vote
1answer
1k views

`set -e` inside a bash function

Does set -e behave differently here set -e; function foo { } vs. function foo { set -e; } does set -e belong inside functions? Does set -e declared outside of functions, affect "nested" ...