Questions tagged [functions]
The functions tag has no usage guidance.
74
questions
1
vote
1
answer
87
views
Create a bash function with parameters to use as an alias
I have realised that my folders follow a specific structure and wanted to access them with cd faster, so I tried to make this alias / function that would behave like this:
cdc glm 03
would be ...
2
votes
2
answers
499
views
Why this func in xargs has error?
Why this coammand has error?
get_year func works.
xargs -I {} -r -n1 cp {} ${Dst}/videos/$(bash -c 'get_year {}')
errors
ls: cannot access '{}': No such file or directory
ls: cannot access '{}': No ...
0
votes
2
answers
97
views
Defining a function in Ubuntu
I am using Ubuntu to access a remote computer where I am doing calculations. I can access information about previously run jobs using the command
sacct --starttime 2022-09-17 --format=JobID,Jobname,...
0
votes
1
answer
322
views
calling bash functions with arguments that have to be quoted
How can I handle the calling of functions that take arguments that have to be quoted?
For instance, consider the following function
time-stamp ()
{
if (( $# == 0)); then
tmstamp="$(date +T%...
0
votes
0
answers
22
views
Validity of local variable declaration
Is these valid local variable declarations in a bash script?
local jf=$1 rc="\e[0m" iq=8 bfcode frmt
local jf=$1 rc="\e[0m" bfcode frmt iq=8
0
votes
1
answer
344
views
Executing bash function from file
I have a bash file with a few functions in it. Is it possible to run a function from the file using the command line?
0
votes
0
answers
28
views
Libreoffice Calc add dupliacte entries
I have a generated csv of items sold with quantity sold, on transaction per line.
There are many transactions of the same items and I would like to automate adding the numbers of the same items.
I ...
0
votes
2
answers
77
views
Not using > makes all the difference in opening gedit through terminal w/o errors or locking the terminal
I have been experimenting with using terminal to open gedit with any type of file it is capable of using and not having the terminal blocked until the file is closed OR have any error messages in the ...
0
votes
0
answers
524
views
Arguments from bash script to ffprobe not correctly interepreted
I have the following function in a bash script. When I execute it, I always get a returned string from the ffprobe command containing an error in the form:
Argument '-' provided as input filename, but ...
0
votes
1
answer
44
views
Help on function options [closed]
I am writing documentation for a bash function that I am writing. It supports a colour option which can be one of --vlt --blu --grn --ylw --orn --pur --red --wht. I have used the following ...
1
vote
1
answer
78
views
Handy command for editing previously executed mistyped command and overwriting history entry with the fixed one
until recently I was pretty sure that fc command opens previously executed command in the default editor, executes submitted changes and overwrites last entry from the bash history. However, seems ...
0
votes
1
answer
256
views
Is it possible to write a bash function to change directory by passing the name of a directory variable?
I want write a function which changes the working directory by passing the name of a directory variable which has already been established like :
foo () {
cd $"$1"
}
However when I try , ...
0
votes
2
answers
3k
views
Bash: Define a function in bashrc that can be used by any scripts globally
I like to define a function in ~/.bashrc and use it in different scripts either via export -f or source .bashrc.
The function:
nano ~/.bashrc
function test_func() {
yt-dlp -f '299+140' --merge-...
1
vote
2
answers
58
views
how to pass exit results to a function
I am trying to reduce the amount of code in a script. What I want to do is pass the result of a command to a function that tells me if the command passed or failed and then exits if it fails.
Here is ...
0
votes
0
answers
236
views
Redefine a function based if user chooses "y"
I use a function called exe() inside some scripts when I want to display the command to be run and then run that command. I wanted to extend this so that, optionally, the person running the script can ...
-2
votes
4
answers
287
views
Can a function only be called if its name is the first word of an expression?
Can a function only be called if its name is the first word of an expression, as is the case with aliases?
Or can it also be the nth word of an expression?
I can't emulate a use case that answers this ...
0
votes
1
answer
82
views
Multiple Aliases triggering same function
I'm trying to create a function, but I want to trigger by either aliases : debugApp, debugApi
Rather than creating 2 functions to do the same thing
debugApp() {
#update .env to generate log
...
0
votes
1
answer
261
views
Bash function used with command and additional parameter
I would like to change my repetitive lines into small function and get rid of unnecessary code.
It can be fuction with dialog command which will have the same parameters, but --msgbox will be always ...
1
vote
0
answers
19
views
youtube-dl - Where does one locate user-created functions ( )? [duplicate]
I'm looking for clarification about an aspect of this question:
Downloading videos to an external drive with youtube-dl
DannyRe's answer is great except that I may not be the only one wondering ...
2
votes
2
answers
145
views
Function that creates a file in a directory
I have 4 directories: dir1 dir2 dir3 dir4. I want to create a file in each directory. I know I can do this: touch file1.txt and then move it to dir1, then touch file2.txt then move it to dir2 but it ...
1
vote
1
answer
316
views
Disable change backgound function
How to disable "change background" function from the Terminal on Ubuntu 18.04? And set one standard background for all the time? Thanks :)
1
vote
2
answers
411
views
Defining function is not working
I want to define this function:
displayInfo (){ echo "Hi";cal;date }
But after pressing enter, this is what I see:
>
What's the problem?
34
votes
3
answers
4k
views
How can I find where certain bash function is defined?
There are many functions that can be used in Bash shell. Their definitions can be listed by set, but how to find in which files certain user defined functions are defined?
0
votes
1
answer
761
views
Save function as alias
I am working on function that will resize and optimize all images in the directory with single command.
So far I created this function
function prepareimages() {
# Resize Images
for img in ...
1
vote
1
answer
930
views
Python 3.6 is required. Current python version is ''2.7.15rcl"
I'm using Ubuntu 18.04. after connecting to docker using sudo docker login
I'm trying to use azure functions on Ubuntu by creating a new function app using func init MyFunctionProj --docker and have ...
1
vote
1
answer
2k
views
Find out how many times a specific function is used in command line terminal
Is there a function to show how many times a specified function has been used? For example if I wanted to know how many times I had used the cp function or whatever?
7
votes
2
answers
5k
views
How can I use an alias in a function?
In my dotfiles I have some functions that rely on aliases or functions to exist for them to work. For some reason, I can get them to reference other functions I have created, but not aliases for ...
2
votes
1
answer
2k
views
bash function implement python command
I have this
python -c "import sys, urllib as ul; \
print ul.quote('sample hihi ')"
How can I wrap it into a bash function, so I can call it like a function like so:
urlencode('sample hihi ')
...
3
votes
2
answers
24k
views
Pass environment variable to bash script, called from within a function
I mean to have:
A bash script scr.sh that takes positional parameters
#!/bin/bash
echo "Params = $@"
echo REMOTE_SERVER=${REMOTE_SERVER}
A bash function f defined in another script scr2.sh
#!/bin/...
1
vote
1
answer
8k
views
How to pass arguments from one function to another function in bash scripting?
I can do this in Python:
def one(arg1):
return arg1
def two(a,b):
result=a+b
return one(result)
two(1,3)
And it will work. But how do I do the same in a bash script?
6
votes
2
answers
1k
views
Dollar Value To Word In LibreOffice Calc
I am wondering if there a way to convert a dollar value into words within LibreOffice Calc version 6.0.3.2
$1932.19
Would Become
One Thousand Nine Hundred Thirty Two Dollars And Nineteen Cents
I'...
0
votes
1
answer
4k
views
Node.js "UserLogged" function returning "undefined". Why? [closed]
When I get to the end of the code below, it always returns "undefined" and I don't know why!
function UserLogged (session) {
if (session === null) {
var err = new Error('Not logged in');
...
12
votes
3
answers
4k
views
Mistake in shell function to count even numbers
For an assignment I have to write a function that prints the number of even numbers when provided with a sequence of numbers.
I used the piece of code I used for a previous assignment (to print 1 ...
2
votes
1
answer
978
views
Why am I getting _parse_usage error on function invocation in bash?
So I was getting the following error:
bash: _parse_usage: line 16: syntax error near unexpected token `('
bash: _parse_usage: line 16: ` -?(\[)+([a-zA-Z0-9?]))'
bash: error importing function ...
2
votes
1
answer
6k
views
How can I make a Bash alias that takes user input?
I have a Bash alias for sending a command to my server like:
alias ssh=sshpass -p "Passw0rd!" ssh -p 9999 -q -oStrictHostKeyChecking=no [email protected] "some_command"
but I want to be able to ...
0
votes
1
answer
3k
views
How to call a function inside another function but in a different shell
I have a shell script with two functions. The second function needs to be run as another user from a new bash shell. The first function is invoked into the second one. Function 1 uses some of the ...
2
votes
0
answers
204
views
FN buttons on Ubuntu 17.04
I have installed Ubuntu 17.04 on Acer v3-571G and I want to bring back my FN function buttons functionality like Volume Up and Volume Down, also Brightness controlling functions.
I have tried so more ...
1
vote
1
answer
14k
views
How do I write a function in Python with a filename as an argument? [closed]
**EDIT:
Sorry if I was unclear. Let me clarify: I'm trying to write a function that takes a filename and a number i as arguments, loads the file specified by the filename with numpy.loadtxt(), and ...
2
votes
2
answers
1k
views
Mathematical operations on arrays from logged lines
quite the bash beginner here.
I am trying to log printed lines into an array via bash.
I would like to perform mathematical operations (i.e. adding up elements at the same position) on certain ...
0
votes
1
answer
1k
views
Capture output of command-not-found
I am writing a bash function that I want to use the output of command-not-found, located on my system in /usr/lib/command-not-found. However, a simple $() does not suffice. The output goes straight to ...
0
votes
1
answer
2k
views
running matlab functions using bash terminal
I had a problem running matlab functions straight from bash terminal on Ubuntu 16.04. I tried following these suggestions but they didn't work. Below I offer my solution.
0
votes
1
answer
1k
views
Bash script fails *only* from cron with “not a valid identifier”
I have a script that creates a new log file each week that can be called from other scripts with a log file parameter. Without any arguments it creates a log with the name of the parent process in ~/...
7
votes
0
answers
4k
views
Is there a Libreoffice Calc function to translate languages?
Is there a Libreoffice Calc function to translate languages? I would like to write words into my spreadsheet and then automatically copy and translate them into german into a new cell.
-1
votes
1
answer
246
views
Where the function, to see date in terminal, is saved? [closed]
I mean, there isn't any function written in ~/.bashrc which can be used for showing date.
2
votes
1
answer
607
views
Function to find filenames containing a string
I am trying to create this function, but I don't find the correct syntax:
function contains {
find . -maxdepth 1 -i -name *$1*
}
The aim is to type contains xxx to get the list of files ...
2
votes
0
answers
90
views
Select photos without rating in Shotwell
I reviewed my photos and set ratings for some of them. After this I wanna delete all photos without any rating. Is it possible to make filter for this (or search criteria)?
0
votes
1
answer
369
views
How can I unfold a bash function that has inner functions in it?
Suppose I source the function myfunction defined by
myfunction(){
myinnerfunction
}
where myinnerfunction is defined as
myinnerfunction(){
echo word
}
I'd like to find an equivalent of ...
4
votes
1
answer
3k
views
bash function cannot change the value of a local variable when called by $()
The following code works differently depending on which way Parse_Short_Switches() is called. After calling the function 'Parse_Short_Switches' by using result=$(Parse_Short_Switches), the value of $...
4
votes
1
answer
493
views
SSH session doesn't export functions
I have a bunch of functions stored in ~/.bash_functions, which is sourced by ~/.bashrc on shell startup. The file exports all the functions like so:
# Find functions in this script based on a grep ...
1
vote
1
answer
303
views
How could one export from a sourced script only specific functions
I try to expose from a script only specific functions.
For example, let's say I have the script hello_world.sh and it has 2 functions, hello and world:
## hello_world.sh - name of the file, not the ...