Questions tagged [functions]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
28 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 ...
0
votes
0answers
45 views

bash function check for n times or exit on success

I have 2 functions to check on password resets coming from AD. I would like it to check for 60 seconds every 5 seconds or exit on the variable "$countdown" = 89 I'm sure it's simple but I'm getting ...
1
vote
0answers
17 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
2answers
53 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
1answer
142 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 :)
0
votes
2answers
59 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?
28
votes
3answers
2k 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
1answer
114 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
1answer
258 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
1answer
512 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?
3
votes
1answer
402 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 ...
1
vote
1answer
349 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 ') ...
1
vote
2answers
9k 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/...
0
votes
1answer
2k 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
2answers
886 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
1answer
2k 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
3answers
3k 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
1answer
250 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
1answer
2k 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 ...
0
votes
1answer
1k 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
0answers
198 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
1answer
5k 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
2answers
604 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
1answer
597 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
1answer
1k 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
1answer
731 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 ~/...
5
votes
0answers
2k 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
1answer
166 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
1answer
301 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
0answers
56 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
1answer
209 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 ...
3
votes
1answer
992 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 $...
3
votes
1answer
272 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
1answer
131 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 ...
0
votes
2answers
747 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 ...
2
votes
0answers
140 views

Redirect 'complete' in bash functions and alias [duplicate]

tl;dr: Is there a way to use an existing auto completion function to also auto complete arguments to an alias or short function. Auto completion in bash is great but does not mix well with aliases ...
2
votes
1answer
759 views

Create folder loop function doesn't work

I have created a function in a .sh file that creates directories in a loop with 3 parameters int: start, end and folder name name But I am getting the following error: Syntax error: "(" unexpected ...
12
votes
1answer
408 views

What does _expand do?

I was working with the shell, and by mistake I autocompleted with tab after writing _e, which resulted in _expand. What does this command do? I couldn't find an explanation online, the only ...
3
votes
1answer
53 views

Finding, moving and removing in Ubuntu

OS: Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-62-generic x86_64) I have a directory like the following: ~/total/ test1/ test1.txt some_other_file_i_dont_care.py test2/ ...
1
vote
2answers
2k views

create scatter plot

file (1. arg) will create (scatter plot) for n. column (x-axis, 2. arg) and m. column (y-axis, 3. arg) function is called myfun sourcefile 1 3 for scatter plot of 1. and 3. column from file ...
3
votes
1answer
126 views

How to execute bash aliases functions in the terminal?

I found out that many people have something like in their /etc/bash.bashrc as aliases: del_recursive() { find . | grep '$1' | xargs rm } process() { ps -ef | grep $1 } apache() { sudo ...
1
vote
1answer
47 views

What is the difference between these python functions?

What is the difference between this: def total(initial=10, *numbers, **keywords): count = initial for fake in numbers: count = count + fake for key in keywords: ...
1
vote
0answers
552 views

Textstat not running functions

I just found the link on how to install textstat on my python idle and I was successful in getting it to work. However, when I import textstat everything seems fine until I try to run a function. It ...
0
votes
1answer
62 views

Where are custom functions located

When I in Ubuntu runs the mario(){echo "Sorry, Mario is in another castle";} in the console, where does this gets saved, and how do I remove the function mario?
1
vote
1answer
55 views

How to enter part of a command automatically, after another command executed?

I want to create a function for grep-ing my command line history by history | grep {keyword}. And after seeing the list and choosing the command by line number ,I want to execute it by !{line_number} ....
13
votes
7answers
8k views

How to make the argument as optional in bash?

In below function with 9 arguments: SUM() { echo "The sum is $(($1+$2+$3+$4+$5+$6+$7+$8+$9))" } I want to make the second arguments to the next(3..9) become a optional arguments. When I call ...
0
votes
2answers
800 views

How can I select all untagged photos in Shotwell?

I would like to be able, to select all untagged and tagged photos in Shotwell separately, so that I may tag and re-tag them. How can I do this?
7
votes
2answers
69k views

How to pass arguments to functions while executing a python script from terminal?

I have a python file named solution.py and I can successfully execute it through the terminal using the following commands: chmod +x solution.py python3 solution.py This works just fine if I have ...
3
votes
2answers
3k views

Num Lock function has changed after upgrading to UBUNTU 13.10 [duplicate]

I faced a strange function I installed ubuntu 13.10 and all the time the number pad on the right of my keyboard is typing number without pressing Num Lock and when I turn it on It does the job when ...
14
votes
3answers
12k views

Where can I put a user-defined shell function?

I am planning to create a function that would simplify things for me. The function would be something like function lazymode() { echo "Hello World!"; } so that when I use the command lazymode in ...