Public bug reported:

Simple function gives different results when interpretator set in first string 
of script
CHECKPROC()
{
i=$(ps aux | grep -c $0)
ps aux | grep -c $0
echo variable is $i
sleep 10
}
CHECKPROC

Expected
In any conditions it will return same values, then will increments when other 
copies of script  will be found in proccesses list.

Happened.
We set interpretator with #!/bin/bash or #!/bin/sh in first string of script 
and runs multiple copies of script from one terminal with & after scriptname. 
It's returns "1" and "variable is 1" always.
Without interpretator setup, when string #!/bin/bash or #!/bin/sh deleted.
Run multiple copies scriptname.sh&
On every iteration it returns right first value and "variable is $value+1"

$scriptname.sh&
2
variable is 3
$scriptname.sh&
3
variable is 4
...and so on.

Without counting in first case it returns only string with grep, in
second case -- one more string with different PID and script name when
called from i=$(...) or i=`...`


Ubuntu 14.04 x32, bash 4.3.11(1)-release
Same results from other man on
GNU bash, version 5.1.16(1)-release (aarch64-apple-darwin21.1.0)
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)


lsb_release -rd
Description:    Ubuntu 14.04.6 LTS
Release:        14.04

apt-cache policy bash
bash:
  Установлен: 4.3-7ubuntu1.7
  Кандидат:   4.3-7ubuntu1.7
  Таблица версий:
     4.3-7ubuntu1.8+esm1 0
       -32768 https://esm.ubuntu.com/ubuntu/ trusty-infra-security/main i386 
Packages
 *** 4.3-7ubuntu1.7 0
        500 http://ru.archive.ubuntu.com/ubuntu/ trusty-updates/main i386 
Packages
        500 http://security.ubuntu.com/ubuntu/ trusty-security/main i386 
Packages
        100 /var/lib/dpkg/status
     4.3-6ubuntu1 0
        500 http://ru.archive.ubuntu.com/ubuntu/ trusty/main i386 Packages

** Affects: ubuntu
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1958060

Title:
  bash returns wrong variable value/call more proccesses?

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+bug/1958060/+subscriptions


-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to