Stack Exchange Network

Stack Exchange network consists of 174 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 [functions]

The tag has no usage guidance.

-2
votes
0answers
23 views

I get sh: 1: “./my file name.sh”: not found error when using system() command in C language in Ubuntu

I have a Bash script (say FIRST.sh) that calls a C program named objective.c. And this objective.c calls another .sh file named as (say)Matrix.sh like const char *command1= "Matrix.sh"; system(...
1
vote
1answer
85 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 ') ...
0
votes
2answers
593 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
96 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?
0
votes
0answers
10 views

Apply a java function to a dockerized software

I want to let a java function able to apply some action to software dockerized in a docker container. How can i establish the needed connection between the java function and the container.
6
votes
2answers
661 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
630 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
2k 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 ...
3
votes
1answer
105 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 ...
1
vote
1answer
1k 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
526 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
188 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
2k 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
211 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
286 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
487 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 ~/...
6
votes
0answers
662 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
114 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.
0
votes
0answers
75 views

Change Screensaver Button

I own a Asus N61VN now with running Ubuntu 16.04 on it. Since I'm new to Linux I'm trying to figure out a lot of stuff to learn fast and set up the system like I want to have it. Now I have problems ...
2
votes
1answer
154 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
29 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
145 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
466 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
199 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
101 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
435 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 ...
3
votes
0answers
133 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
314 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
366 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
52 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
105 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
46 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
505 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
52 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
49 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
6k 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
652 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?
3
votes
2answers
53k 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 ...
12
votes
2answers
9k 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 ...
3
votes
2answers
1k views

How to get original system command after overwriting it with a function?

I'm at a Hackathon right now so if someone would answer this soon, you'd be doing me a huge favor. I've written a function called ls() in my .bashrc that looks like this: ls() { if(some condition)...
18
votes
2answers
35k views

How can I protect parentheses passed to a cd command? [duplicate]

I asked here how to make cd protect spaces. Tab completion is great, but sometimes you paste the path from the clipboard so this is useful. The solution breaks with parentheses however. No matter how ...
3
votes
1answer
353 views

Saw an interesting command but can't alias it

Saw an command from this post https://askubuntu.com/a/266839/75967 that I would like to alias find {,/usr}/{,s}bin -printf '%f\0' | xargs -0 whatis | sort | less I assume the less or the | is ...
1
vote
1answer
170 views

Extending postgresql code

In postgresql source code there is a file called postgres.c precisely in /src/backend/tcop/. Inside there is a function called exec_simple_query. I want add a line that call my_function that is in ...
3
votes
0answers
98 views

When I'm on the desktop and I type anything a small window opens. What is it? [duplicate]

Possible Duplicate: What is the text box on the desktop for? When I'm on the desktop of Ubuntu, I type something and it appears in a small window in the lower right corner of the screen. What is ...
5
votes
2answers
167 views

How do you print/recall the definition of a function in bash

I can define and print the contents of variable called my_var like this: my_var="hello" echo $my_var but if I define: my_funct {echo "hello";} how can I recall my function's definition later on?
2
votes
2answers
665 views

How to bind multiple commands

We all have to use ls |more and also some other commands. So i just need info is there a way to bind multiple commands together like I want to bind ls|more together.So when i simply pass ls command ...
3
votes
2answers
154 views

Batch Starting Servers

How I can create a batch alias for bash? I need to do this: cd /somefolder bundle exec unicorn -p 3000 rackup faye.ru -s thin -E production bundle and rackup - this is 2 servers for example I want ...