All Questions
14 questions
1
vote
0
answers
34
views
Variable not available outside function [duplicate]
I'm having difficulties understanding the following example I created.
The variable glob_var gets changed inside the test() function, but the original value remains outside of the function:
test() {
...
1
vote
2
answers
1k
views
Entr: trying to trigger function while monitoring file change
I'm trying to monitor some files with entr.
My script based on their examples:
do_it(){ echo Eita!; }
while true; do ls folder/* more-folder/* | entr -pd do_it; done
>> entr: exec do_it: No ...
0
votes
1
answer
2k
views
Calling a function within a pipe
I have a script using a pretty long pipe quite a lot of times.
The middle of each pipe is the same command chain. Only the beginning and the end defers all the time it is used.
Different-command-1 |
...
0
votes
1
answer
751
views
Expand bash variable within piped command [closed]
This is the function that I'm using–or trying to use–to restore a database in a docker container:
function restoredb()
{
# source: see above
local wkdir="pwd | rev | cut -d "/" -f1 | rev"
...
2
votes
1
answer
638
views
What exactly is the function piping into the other function in this fork bomb :(){ :|: & };:?
There are a couple of questions related to the fork bomb for bash :(){ :|: & };: , but when I checked the answers I still could not figure out what the exactly the part of the bomb is doing when ...
0
votes
2
answers
55
views
How to store the data given to a function on standard input?
> cat b.txt
function first
{
foo=$(SOMEMAGIC)
}
echo nyi | first
>
Question: How can we give the "nyi" string to the "foo" variable inside the function? So how can we give the ...
3
votes
1
answer
84
views
Function in function will not be called multiple times if requested?
> cat b.txt
function first
{
sleep 1
echo $(echo $$)
}
function second
{
openssl enc -aes-256-cbc -k "$(first)"
}
echo nyi | second | second | second
>
> time ...
29
votes
6
answers
28k
views
Bash function that accepts input from parameter or pipe
I want to write the following bash function in a way that it can accept its input from either an argument or a pipe:
b64decode() {
echo "$1" | base64 --decode; echo
}
Desired usage:
$ ...
7
votes
1
answer
968
views
Cannot grep jobs list when jobs called in a function
I can grep the output of jobs, and I can grep the output of a function. But why can't I grep the output of jobs when it's in a function?
$ # yes, i can grep jobs
$ jobs
[1]+ Running vim
[2]+...
0
votes
1
answer
269
views
Pipe encrypted archive to uploader
Assume, I do archive several files with this functions:
gen_password ()
{
gpg --gen-random 1 "$1" | perl -ne'
s/[\x00-\x20]/chr(ord($^N)+50)/ge;
s/([\x7E-\xDB])/chr(ord($^N)-93)/...
0
votes
1
answer
53
views
Creating a function that reads off an input list of files
I am in the process of writing bioinformatics pipelines.
These pipelines take in input files and pass them through multiple packages.
Say there is a list of files that goes file1, file2, file3... ...
6
votes
1
answer
381
views
Function to simplify grep with an often used log
I'm trying make a function that simplifies grepping a log I have to work with on a regular basis.
I'd like to use extended regexp with it pipe and redirect the output, etc.
But I'm having trouble ...
4
votes
2
answers
2k
views
How to use a bash function like a regular command in a pipe chain?
I'm performing several commands on large files from within a bash script. In order to monitor the progress I use the pv command.
An example command could look like this
cat $IN_FILE | pv -w 20 -s $(...
5
votes
3
answers
1k
views
Can you pipe to a .bash_profile function?
I received a great function for highlighting files in Apple's finder using the command-line. It's basically a wrapper for osascript.
I got it from Mac OS X: How to change the color label of files ...