Skip to main content

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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
22 views

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....
lachin's user avatar
  • 19
5 votes
2 answers
267 views

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 ...
Rainer Glaschick's user avatar
2 votes
1 answer
170 views

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 [[ &...
AlMa0r's user avatar
  • 1
3 votes
1 answer
76 views

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 ...
Harald's user avatar
  • 1,040
0 votes
2 answers
221 views

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, ...
pglpm's user avatar
  • 162
0 votes
2 answers
237 views

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." ...
Aderbal Nunes's user avatar
1 vote
1 answer
92 views

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 ...
branco's user avatar
  • 13
1 vote
2 answers
730 views

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 ...
Seamus's user avatar
  • 3,904
0 votes
0 answers
223 views

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, ...
noxen's user avatar
  • 1
2 votes
2 answers
89 views

I have following in a bash script: echo "status: [$status] and message: [$message]" if [ "${status}" -eq 0 && "$message" = "ERROR" ]; then echo &...
Nullpointer's user avatar
1 vote
1 answer
153 views

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 ...
pmor's user avatar
  • 757
0 votes
0 answers
103 views

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 ...
d-b's user avatar
  • 2,077
0 votes
1 answer
223 views

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 ...
Kuba0040's user avatar
0 votes
2 answers
917 views

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 ...
user avatar
0 votes
1 answer
44 views

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 ...
andreee's user avatar
  • 203
0 votes
1 answer
93 views

I'm struggling with files and directory permissions. ls -l is telling me something that test -w contradicts. $ ls -l total 1792 -rw-r--r-- 1 root www-data 168 Jan 29 23:53 CODE_OF_CONDUCT.md -rw-...
rhommet's user avatar
0 votes
1 answer
67 views

I am currently working in a project which is Linux based. From Linux terminal I have connected to our web application. The web application consists of pages and data in it so from Linux terminal I use ...
Jeevan Jitu's user avatar
0 votes
1 answer
131 views

There may be a duplicate somewhere (I guess), but I didn't find it so: Why do I see in some scripts those kind of tests: if [ x"$quiet_boot" = x0 ] with an x added before the actual ...
Totor's user avatar
  • 21.2k
1 vote
1 answer
405 views

If there are spaces around the operator, test returns the correct value of the expression. But if there are no spaces, it doesn't throw any syntax error and always return true. $ test "A" == ...
robertspierre's user avatar
0 votes
1 answer
226 views

I am new at unix, I'm trying to learn the bash language, and when I went to the "Testing expression", I found this one: [[ "whatever" =~ h[aeiou] ]] I already read the answer to ...
andr.lex's user avatar
2 votes
3 answers
6k views

I have a hardware watchdog, what is a good way to test that it actually works? Is there a standard script or such to set my system in an infinite loop to hog all resources or such to the point of ...
Matt Welander's user avatar
0 votes
1 answer
3k views

I am doing a basic question for adding, product, subsraction, division by taking user input in first and second I don't understand where am I going wrong because it's not passing any test case. ...
Prince's user avatar
  • 3
13 votes
6 answers
7k views

I need to check that a directory (let's call it dir) contains one of two files (let's call them filea and fileb), but neither none nor both. The ideal solution would be to use a XOR operation between ...
joH1's user avatar
  • 948
2 votes
2 answers
154 views

For the sake of this question, assume that the glob /a/b/c/* produces no matches. This means that the following test should fail (in other words, it should produce a non-zero $?): [[ -n /a/b/c/*(#qN) ]...
kjo's user avatar
  • 16.4k
4 votes
2 answers
2k views

I just wanted to understand the meaning of the following statement and whether they seem correct. test -x /usr/bin/find || exit 0 Command 1 Command 2 Command 3 The output of test -x /usr/bin/find is ...
Dawson Smith's user avatar
0 votes
1 answer
462 views

First I follow this answer then I search about test -v then https://linuxcommand.org/lc3_man_pages/testh.html shows that there is an R option. test -R seems related to name preference. Then I search ...
jian's user avatar
  • 597
8 votes
3 answers
1k views

In bash, the conditional expression with the unary test -v myvariable tests wether the variable myvariable has been set. Note that myvariable should not be expanded by prefixing it with a dollar, so ...
db-inf's user avatar
  • 333
17 votes
2 answers
4k views

I'm perplexed but still guess I misunderstood Bash somehow. /$ if [ -e /bin/grep ]; then echo yea; else echo nay ; fi yea /$ if [ ! -e /bin/grep ]; then echo yea; else echo nay ; fi nay /$ if [ -a ...
Martian2020's user avatar
  • 1,491
0 votes
1 answer
2k views

I'm trying to detect if a process (goland.sh) is running. I used this: #!/bin/bash if pgrep "goland.sh" >/dev/null 2>&1 ; then echo "running" exit 1 fi echo &...
Dean's user avatar
  • 494
2 votes
1 answer
421 views

Consider the following: echo "hello" > file.txt is_match1 () { local m m=$(cat "file.txt" | grep -F "$1") if [ -z "$m" ]; then return 1 fi } ...
fuumind's user avatar
  • 449
8 votes
1 answer
2k views

In a dockerized Alpine 3.14.2 running Bash 5.1.4(1), I encountered a strange behaviour in a Bash script. The essential line is a test for executability of a file, which always fails. This is the if ...
gendergap's user avatar
  • 151
0 votes
1 answer
2k views

If i want to combine the -a and -o script operators in an if statement, how could I do that? For example: if [ ( -e file.txt -a -r file.txt ) -o ( -e file2.txt -a -r file2.txt ) ]; then .... fi Can I ...
zak's user avatar
  • 11
6 votes
3 answers
29k views

I am using solutions from Test if a command outputs an empty string. In addition to those solutions, I want to print command's output if its not empty. I was wondering would it be possible to print ...
alper's user avatar
  • 507
0 votes
3 answers
634 views

When I try the following expression in bash I get a strange error message: [: -lt: unary operator expected First the function definition some_func () { (( 3 + 5 )) } And the expression [ $(...
von spotz's user avatar
  • 515
0 votes
1 answer
1k views

I am trying to create a simple bash script to read user input and use this input as a variable within my script. It currently looks like this : echo "Please specify file:" read FILE What I ...
user avatar
2 votes
1 answer
312 views

I have a book that stated: "....For example, if the shell variable symbol contains an equal sign, look at what happens if you try to test it for zero length: $ echo $symbol = $ test -z "$...
Jacky's user avatar
  • 161
-3 votes
3 answers
217 views

I need to test if an input it has the fromat of a car plate (0000-XYZ) and from the japanese ZIP wich the format is 000-0000
Zeninツ's user avatar
  • 129
4 votes
1 answer
1k views

I am attempting to do a comparison before I append conditions to a profile.d file A grep -F 'TMOUT' /etc/profile.d/sh.local shows me exactly what I expect however the test is always showing true. In ...
MikeG's user avatar
  • 143
1 vote
1 answer
1k views

I am writing a bash script to makup the MariaDB instance on a Synology box. When I run it, it works, but I get an error: admin@synology:/volume1/@appstore/MariaDB10/usr/local/bip$ ./mysql_backup ./...
symcbean's user avatar
  • 6,359
3 votes
2 answers
7k views

I am relatively new to shell (just now the basics of it). I am trying to make sense of a script in order to fix a bug and I stumble upon something that I can't find an answer through Google(probably ...
joeCarpenter's user avatar
1 vote
2 answers
3k views

I am new to Gnu/Linux and bash, and I am trying, unsuccessfully, to write a simple bash script to test if date +%H is within a predefined range of hours. Example: hour='date +%H' if [[ $hour -ge 12 ]] ...
tigger's user avatar
  • 13
0 votes
0 answers
796 views

I have a self written script like (./myscript) and I want to call some commands in that script. So I want to learn how to inject commands into a shell script like this one: #!/bin/bash set -x if ...
MrPython's user avatar
  • 219
0 votes
0 answers
359 views

I'm looking for preferably a one-liner that drops a directory tree a few layers deep with files that contain "realistic" data, as in, not /dev/zero nor /dev/urandom. Data that noticeably ...
Daffy's user avatar
  • 465
-1 votes
1 answer
838 views

I got plenty possible variables in a form of [a-z][0-9], eg 1 letter and 1 number. Is there a way to test them in dash? Something like: myvar=o7 if [ $myvar=o[0-4] ]; then "do this" elif [ $...
user avatar
0 votes
3 answers
690 views

I'm trying to compare the state of more than two variables. The use-case is a script that, among other options, should select (or auto-select) only one of several "modes" based on available ...
secemp9's user avatar
  • 2,522
4 votes
3 answers
1k views

Is it possible to have a conditional within /etc/rc.local? I've checked many Q&As and most people suggest running chmod +x on it, but my problem is different. It actually does work for me without ...
aderchox's user avatar
  • 771
12 votes
1 answer
6k views

Single square brackets [ and testcommand both are built in the bash shell. Why are there two separate commands if both square brackets [ and test commands have the same function?
testter's user avatar
  • 1,510
0 votes
1 answer
791 views

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
0 votes
3 answers
4k views

Is there a way to use a Filename Expansion within a test expression, more specifically, a bash conditional expression? For example: [[ -f foo* ]] && echo 'found it!' || echo 'nope!'; ... will ...
Ricardo's user avatar
  • 111
3 votes
1 answer
2k views

I am learning the zsh in the conditional expressions part, and I found some unreasonable output. For example: $ mkdir emptyspace && cd emptyspace $ var_assigned_with_emptystring="" $...
Anon's user avatar
  • 425

1
2 3 4 5
8