Skip to main content

All Questions

Tagged with
0 votes
1 answer
31 views

function that allows different outputs dependent on argument values

With the following function I want to be able to call it with nico-usage or with a numeric value to print a different string. Con this be cleaned up or made easier. nico-usage () { local ...
Vera's user avatar
  • 1
0 votes
1 answer
98 views

Passing file types to bash function and calling find

I have the following bash function to print between two line numbers, for files watching file types .texi and .org recursively in a particular directory. I would like to be able to supply the file ...
Pietru's user avatar
  • 393
1 vote
1 answer
162 views

Adding help option for function

I have the following function that print NUM lines from the beginning of a set of files. The command (function, script, whatever) accepts a variable number of arguments, and I would like to reserve ...
Pietru's user avatar
  • 393
1 vote
1 answer
3k views

call function by name with arguments

I'm quite new on the shell scripting front and was wondering whether it is is possible to call a function which itself than calls another function with none, one or multiple arguments. The first ...
John_Doe's user avatar
-1 votes
1 answer
123 views

Unable to pass an argument to a function

For my homework, I need to have a function in my code to earn extra credit. I have a script that takes the second argument and makes a folder from what is passed. The code works with the argument ...
Kyle Heath's user avatar
5 votes
3 answers
1k views

Find exec sh: Shell variable not getting passed to subshell

Here is a simplified code that prints the name of Directory if it contains a Filename with same name as the parent directory and .md extension. FIND(){ find . -type d -exec sh -c ' for d ...
Porcupine's user avatar
  • 2,146
3 votes
1 answer
1k views

Get and set the script arguments from within a function in bash

Context: I have an old bash script with a big section parsing its arguments. It happens now that I need to call this section twice, so I plan to move it to a function to avoid code duplication. ...
Jacques's user avatar
  • 561
0 votes
1 answer
1k views

Using loop in script for command line arguments

So I am trying to sort files with specific extensions into specific folder (ones that have been chosen by user by command line arguments) Lets say $1 (.jpg) $2 (.docx) etc The script is all working ...
Viktor Surányi's user avatar
2 votes
6 answers
3k views

Applying commands to lists

Very often I need to apply a certain simple function to a list (or more precisely to a string where substrings that I want to treat as separate items are delimited by a new line). Say I need to ...
Kvothe's user avatar
  • 453
1 vote
1 answer
67 views

Loop function with arguments in another loop function with arguments

# Print $1 $2 times function foo() { for (( i=0; i<$2; i++ )); do echo -n $1 done echo } # Print $1 $2x$3 times function bar() { for (( i=0; i<$3; i++ )); do foo ...
6equj5's user avatar
  • 63
0 votes
1 answer
2k views

How to pass list of arguments into a function

I want to pass arguments from a loop into a function func. For simplicity let's say we are working with the loop for x in {1..5} do for y in {a..c} do echo $x$y done done I'm just ...
CharacterClass's user avatar
0 votes
1 answer
357 views

Shell Function: Sequence of Pipelines as Argument

I have a shell function (in .bashrc) which creates a temp file, executes the arguments (including all sequence of pipelines), redirects it to a temp file and then open it in VS Code. I invoke the ...
Porcupine's user avatar
  • 2,146
1 vote
1 answer
2k views

How to make my bash function known to external program

I have bash functions foo and bar in my ~/.bashrc. Function foo calls an external command ext_command that itself takes as one of its arguments another command. I want to pass bar as that command, i....
Bananach's user avatar
  • 455
2 votes
1 answer
237 views

Does the system-wide limit on argument count apply in shell functions?

The other question asks about the limit on building up commands by find's -exec ... {} +. Here I'd like to know how those limits compare to shells' inner limits. Do they mimic system limits or are ...
user avatar
1 vote
4 answers
112 views

Pass function argument to defined variable

How can I "inject" a function argument to a defined variable like in this example? mood="i am $1 happy" happy () { echo "$mood" } happy "very" Current output: i am happy Desired output: i am ...
bone's user avatar
  • 13

15 30 50 per page