Questions tagged [positional-parameter]

75 questions
2
votes
2 answers

How to disable special characters in bash?

I've created a script which performs a calculation. For example: count 1 + 3 1 + 3 = 4, - and / also works, but if I type count 1 * 3, I got Should be number operand number Here is a part of a script: if [ "$#" -ne 3 ]; then echo "Should be…
Josh
  • 33
  • 1
  • 7
1
vote
0 answers

Can you change parameter inside an if statement

I'm new to bash, and am asking if I can change the parameter value inside an if statement. However, im getting an error of: attempted assignment to non-variable (error token is "=27-26") The code i'm running is if (( $1 > 26 )) then let…
New coder
  • 9
  • 2
1
vote
1 answer

Powershell A positional parameter cannot be found that accepts argument '10'. While not even using a positional parameter

Note that the example code is contrived and is meant for illustration of the problem only. I wanted to make a function in powershell to get some random numbers but i'm running into the very weird issue that when i dont use the position defining of…
smvd
  • 101
  • 1
  • 8
1
vote
3 answers

How to use positional argument with embed quotes in bash?

I'm trying to create a bash script that automates configuration of some letsencrypt related stuff. The file that I have to edit is json so I would just use jq to edit it and pass the site name to it from the positional arguments of the script, but I…
The amateur programmer
  • 1,084
  • 1
  • 15
  • 31
1
vote
2 answers

Bash - how to get a last character of a positional Parameter?

I am trying to read a last character of a string saved in a positional parameter $1. So far, I know how to do this only for the named variable, such as echo "${str: -1}" Could someone advise me how to do it for $1. Thought this could work, but it…
Jozef
  • 323
  • 4
  • 23
1
vote
1 answer

How to make argparse treat all arguments as positional?

How can I make an argparse parser treat all arguments as positional, even the ones that look like options? For example, with this definition: parser.add_argument('cmd', nargs='*', help='The command to run') I want to be able to run prog.py mycomand…
planetp
  • 10,603
  • 14
  • 62
  • 124
1
vote
0 answers

pandas dataframe calling apply as a class variable: takes 1 positional argument but 2 were given

I am running into a weird python error that I could not understand: import pandas as pd import numpy as np def logit(p): if 0 < p < 1: return np.log(p / (1 - p)) elif p == 0 or p == 1: return pd.NA else: raise…
qkhhly
  • 1,010
  • 3
  • 10
  • 22
1
vote
1 answer

How to pass positional arguments to an interactive bash session

I wanted to start an interactive bash shell like this : bash (...some options) 1 2 3 so that in the shell session, I have $1=1, ... I didn't find any options to achieve the effect. I tried this, thought it might work : bash -c bash _ 1 2 3 but it…
Philippe
  • 8,203
  • 1
  • 14
  • 17
1
vote
1 answer

An argument that can be supplied in both positional and keyword ways?

In Python, a positional argument can always be supplied as a keyword argument (we're not digging into Python-C extensions where this may be false): def foo(bar=None): print(bar) foo("aaa") foo(bar="aaa") I want to achieve the same effect as…
iBug
  • 30,581
  • 7
  • 64
  • 105
1
vote
1 answer

SystemError is raised after attempt to create function with positional-only args in runtime inside other one

There is some test code: some_type = int def func0(): def func1(arg: some_type, /): pass func0() And I get the following error: Traceback (most recent call last): ... SystemError: no locals when loading 'some_type' However the code…
1
vote
0 answers

Command line using an array with spaces

How can I pass an array where some values have spaces. I mean: script.sh #/bin/bash echo $1, $# I can run this little script $ ./script.sh a --> a, 1 $ ./script.sh "a b" --> a b, 1 $ v=("a b" c) $ ./script.sh ${v[@]} --> a, 3 $ ./script.sh…
user721730
  • 341
  • 5
  • 7
1
vote
1 answer

Bash - How to pass array to function, with index defined in new function

I have this current function used to create an array in a menu style (associative arrays can't be used in the scenario). declare -a array1=("host1" "host2" "host3") declare -a array2=("ip1" "ip2" "ip3") function menusetup { iter=0 for ((i=0;…
1
vote
1 answer

completion Candidates for positional parameter in picocli

I'm trying to provide completion for positional parameters. Somewhere I found note that they are not very well supported, but currently I'm not able to find exact place in spec and I'm not sure what that really means. In meantime I found…
zimi
  • 1,526
  • 10
  • 25
1
vote
3 answers

bash function with three to infinitely arguments

Lets assume I have some python argparse script which I would like to kind of alias using a bash function. Let us assume this python script takes four arguments: --arg1 --arg2 --arg3 --arg4 What I would like to achieve is taking the first two…
Peterhack
  • 651
  • 1
  • 8
  • 22
1
vote
1 answer

How do you specify both static and dynamic positional parameters in Powershell?

EDIT As per The Mad Technician's suggestion, I have submitted a bug report for this on the PowerShell UserVoice site:…