Thursday, April 25, 2024
14
rated 0 times [  14] [ 0]  / answers: 1 / hits: 22897  / 2 Years ago, sun, october 2, 2022, 3:21:33

I tried the following small simple script:



#!/bin/bash
$1="bar"
echo $1


But when I run ./script foo I get error and the value is not changed:



/home/mika/script: line 2: foo=bar: command not found
foo


I know $1 is the first argument you pass to your script. But even like this I want to change its value.


More From » command-line

 Answers
1

You can use the builtin set:



#!/bin/bash
set -- "bar"
echo $1


Source and more about: Change a command line argument - bash.


[#26278] Monday, October 3, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
fulild

Total Points: 239
Total Questions: 103
Total Answers: 112

Location: Papua New Guinea
Member since Thu, Jul 9, 2020
4 Years ago
;