Questions tagged [test]
This is about the Unix utility "test," also invoked as "[", or its shell syntax [[ … ]] variant. For questions about testing software and setups, use the "testing" tag.
370 questions
0 votes
1 answer
52 views
Testing postfix mail server with POP3 fails
PostfixAdmin installed successfully. To test whether internal sending and receiving mail work, I used SMTP to send mail: telnet mail.example.com 25 Trying 94.284.174.110... Connected to mail.example....
5 votes
2 answers
282 views
Why are there so many shell scripts using "x$var" = "xabc" instead of "$var" = "abc"? [duplicate]
In the old times of DOS batch scripts, the only way to check for a variable to be empty or to allow an empty variable was to prepend (or append) a known letter, commonly the letter x, because there ...
2 votes
1 answer
185 views
Semicolon in conditional structures after the closing double bracket in a bash/zsh script?
Continuing Semicolon in conditional structures (which handles single brackets), what's the point of having a semicolon after the closing DOUBLE bracket ]]? In my tests, running #!/bin/zsh -- if [[ &...
3 votes
1 answer
86 views
Why can't I have a single quote in a bash associative array index when testing with `test -v` [duplicate]
When I run the following code declare -A X # get an associative array index="a'b" # a somewhat weird index X[$index]="this is set" echo "<<${X[$index]}>>" if ...
0 votes
2 answers
257 views
How to stop a running memtester (without risking to have to reboot)?
Extremely "noob" question: I have a running sudo memtester ... on an Ubuntu 22.04 machine, but I gave it too much memory to test and it's taking too much time (I see it running and updating, ...
0 votes
2 answers
256 views
How to check value inside a file using bash?
I'm trying to check if the value inside a file is "0". COUNT_EXECUTION=$(< /tmp/count) if [ "$COUNT_EXECUTION" == "0" ]; then echo "Try restart service." ...
1 vote
1 answer
111 views
I fail to match the standard output of a posix shell function with the text I want to test it against
I want to test if the output of a function matches the text I envision it should write to standard output. But the code below never prints test PASS and I can't figure out why. I also tried putting ...
1 vote
2 answers
745 views
Is my "escaping" wrong - or is it something else?
Here's what I'm trying to do (in a script): #!/usr/bin/env bash if [[ ! $("/usr/bin/scp [email protected]:/Users/seamus/Downloads/imgutils/image-utils* /home/pi/testscp") ]]; then ...
0 votes
0 answers
228 views
Linux From Scratch 12.1 GCC testsuite failing and timing out
I'm currently building Linux From Scratch 12.1 with the book, I've followed the instructions line by line. I'm struggling with the GCC testsuite, I have lots of FAIL and timeout. In addition to that, ...
2 votes
2 answers
97 views
Bash complaints about missing ], while it is there [duplicate]
I have following in a bash script: echo "status: [$status] and message: [$message]" if [ "${status}" -eq 0 && "$message" = "ERROR" ]; then echo &...
1 vote
1 answer
164 views
Why does -n with unquoted variable containing empty string return true? [duplicate]
From man bash: -n string True if the length of string is non‐zero. Examples: # expected $ var=""; [ -n "$var" ]; echo $? 1 # unexpected? $ var=""; [ -n $var ]; echo ...
0 votes
0 answers
110 views
Shell script: check for file doesn't work if there is a symlinked directory involved?
If I have /mydir/myfile.txt this code echos file already exists if [ ! -f "/mydir/myfile.txt" ]; then touch "/mydir/myfile.txt" echo "created file" else echo ...
0 votes
1 answer
227 views
"while" loop is not reading reading a variable's contents
I have setup a little script to illustrate my problem. I have set up a while loop that I would like to keep looping as long as $output is equal to No screen session found #!/bin/bash echo Stopping ...
0 votes
2 answers
927 views
Syntax error: "(" unexpected (expecting "fi") when using calculations
I am relatively new to shell, and I am getting a syntax error where I am still confused. #!/bin/dash ls="ls -l test" small=0 medium=0 large=0 for i in $(seq 11 9 56) do filename=$(echo ...
0 votes
1 answer
53 views
Why does the test command apparently choke on a for loop variable?
I want to determine all broken symlinks within a directory. In ignorance of a better solution, I tried this simple bash one-liner (bash version is 4.2.46, which may be worth mentioning because it's a ...