Skip to main content

Questions tagged [assignment]

The tag has no usage guidance.

-1 votes
1 answer
255 views

Zsh string variable containing multi words must be assigned to an array

How to have Zsh string variable containing multi words separated by space be assigned to an array so that each word is the array element s='run help behind me' a=($s) m=${a[0]} n=${a[1]} print "m=...
user avatar
1 vote
1 answer
86 views

How to iterate over a directory for files without including sub-directories in Bash

I need to parse through a directory that contains files and subdirectories however I am unable to use the find command. The for loop is supposed to go through each file and compare it to another ...
IMPNick's user avatar
  • 11
9 votes
2 answers
770 views

In POSIX scripting, is x=$y always equivalent to x="$y"?

Are x=$y and x="$y" always equivalent? Didn't know how to search for this. So far, I've always been using x="$y" to be "on the safe side". But I used x=$1 at one point ...
finefoot's user avatar
  • 3,142
-1 votes
1 answer
51 views

Grouping commands of if...then statement, including assignation of variable for shell/bash in a single line

I know the existence of while-do-done. Alternatively, I know that I can use for-do-done. But, I was trying to test manually using if-then-else. I would to like to execute a command, but doing a shift ...
joseluisbz's user avatar
0 votes
1 answer
430 views

Assigning $* in shell script from args array

After iterating thru the shell arguments and filtering out unwanted arguments into an array, I want to assign the array back to $*. For example, in the below script, I want to remove the arguments -f ...
user3118280's user avatar
1 vote
0 answers
1k views

Completely disable NetworkManager from using DHCP client?

I am using RHEL 7.9. This version of RHEL I use nmcli and nmtui to configure network connections. Problem: NetworkManager service appears to be filling up journalctl logs with the following output Apr ...
Dave's user avatar
  • 621
7 votes
2 answers
568 views

why is zsh not expanding this glob defined inside a function '(:a)'

The second line of the script only works if I trigger glob expansion by executing echo. I can't understand why. Here's the command and it's execution to give some context. Function definition: ~/ cat ~...
bryan hunt's user avatar
0 votes
2 answers
2k views

How to move home using relative path [closed]

The question is "Your current directory is cambridge. Move to your home directory using a relative pathname (don't use cd by itself for this move)" but I cannot for the life of me figure it ...
AASFLC's user avatar
  • 3
0 votes
0 answers
88 views

Variable assignment echo $VAR in subshell is a good method or not? (Nested bash functions)

I'm not a BASH programmer and whenever I have to create scripts it's a lottery for me, so apologies if my script looks too redudant or written by a newbie. As a foreword I have many screen snapshots ...
Alex's user avatar
  • 21
0 votes
1 answer
413 views

one line definition of a variable conditional on the output of a logical test

In bash programming I've always defined conditional variables in the following long hand way dog=1 if [[ $dog -eq 1 ]] ; then cow=1 else cow=0 fi This is obviously incredibly inefficient. In ...
Leo Simon's user avatar
  • 453
8 votes
2 answers
4k views

changing IFS temporarily before a for loop [duplicate]

I know that the SHELL allows variable assignment to take place immediately before a command, such that IFS=":" read a b c d <<< "$here_string" works... What I was ...
computronium's user avatar
1 vote
1 answer
748 views

Result of a command is not assigned to a variable

I am pretty unexperienced (to put it mildly) when it comes to BASH and Shell scripting, so bear with me: $ toda=$(date) | echo $toda gives me: Fr 29 Mai 2020 15:25:19 CEST. So far so good. datediff ...
Guebert's user avatar
  • 13
0 votes
3 answers
6k views

Assign to a variable in a bash script

I have the following script and I try to create an empty text file. I tried touch and I tried echo -n > - they both fail. #!/bin/bash set filename_result="contents" echo "filename=$...
andrewz's user avatar
  • 153
4 votes
1 answer
107 views

$-expansions not performed as expected when following a redirection

It seems that bash and zsh will perform the variable and arithmetic expansions in a child process when a) they're following a redirection operator like <, >, >> or <<<. b) the ...
user avatar
9 votes
5 answers
10k views

Assign the same string to multiple variables

I want to assign the string contained in $value to multiple BASH variables. Actually the example I gave before (var1=var2=...=$value) was not reflecting exactly what I wanted. So far, I found this but ...
SebMa's user avatar
  • 2,209

15 30 50 per page