Questions tagged [functions]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
-2 votes
0 answers
34 views

Using bash functions with arguments with if conditions

I am using Ubuntu 20.04 LTS and have written a function isnum that verifies integer values. I use it with an if statement. if isnum "$var"; then I guess that I can also use it as follows ...
user avatar
  • 23
0 votes
1 answer
34 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%...
user avatar
  • 1
0 votes
0 answers
11 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
user avatar
  • 35
0 votes
1 answer
42 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?
user avatar
  • 35
0 votes
0 answers
27 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 ...
user avatar
  • 1
0 votes
2 answers
35 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 ...
user avatar
0 votes
0 answers
112 views

How to source and call a function within another function?

To my use case, I'm trying to accomplish calling on a function inside another function sourced from a different script. As you can see below, script1.sh is only called upon and wouldn't work if not ...
user avatar
0 votes
0 answers
152 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 ...
user avatar
  • 337
0 votes
1 answer
41 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 ...
user avatar
1 vote
1 answer
39 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 ...
user avatar
  • 31
0 votes
1 answer
50 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 , ...
user avatar
0 votes
1 answer
438 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-...
user avatar
  • 1,861
1 vote
2 answers
55 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 ...
user avatar
0 votes
0 answers
138 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 ...
user avatar
  • 243
-2 votes
4 answers
258 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 ...
user avatar
0 votes
1 answer
48 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 ...
user avatar
  • 155
0 votes
1 answer
165 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 ...
user avatar
  • 53
1 vote
0 answers
18 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 ...
user avatar
  • 11
2 votes
2 answers
103 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 ...
user avatar
  • 113
1 vote
1 answer
211 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 :)
user avatar
1 vote
2 answers
300 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?
user avatar
  • 71
32 votes
3 answers
3k 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?
user avatar
  • 4,719
0 votes
1 answer
400 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 ...
user avatar
  • 103
1 vote
1 answer
717 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 ...
user avatar
1 vote
1 answer
1k 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?
user avatar
5 votes
1 answer
2k 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 ...
user avatar
  • 578
2 votes
1 answer
1k 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 ') ...
user avatar
2 votes
2 answers
21k 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/...
user avatar
0 votes
1 answer
6k 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?
user avatar
  • 65
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'...
user avatar
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'); ...
user avatar
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 ...
user avatar
  • 147
2 votes
1 answer
629 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 ...
user avatar
2 votes
1 answer
5k 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 user@192.168.1.15 "some_command" but I want to be able to ...
user avatar
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 ...
user avatar
  • 4,853
2 votes
0 answers
203 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 ...
user avatar
1 vote
1 answer
11k 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 ...
user avatar
  • 13
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 ...
user avatar
  • 145
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 ...
user avatar
  • 2,060
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.
user avatar
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 ~/...
user avatar
7 votes
0 answers
3k 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.
user avatar
-1 votes
1 answer
224 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.
user avatar
2 votes
1 answer
489 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 ...
user avatar
  • 133
2 votes
0 answers
74 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)?
user avatar
0 votes
1 answer
328 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 ...
user avatar
  • 2,246
4 votes
1 answer
2k 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 $...
user avatar
  • 61
4 votes
1 answer
437 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 ...
user avatar
  • 13.5k
1 vote
1 answer
257 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 ...
user avatar
0 votes
2 answers
971 views

Cannot apply 'stat' command for given parameters

I want to make a small shell script that shows all the files in a file tree starting from a given directory that have the given user and size greater than a given size. Hence, my script will take as ...
user avatar