Search results

  1. J

    checking commands in script

    The below works without any external processes: if ! command -v perl >/dev/null 2>&1; then # something wrong fi Note that a builtin, function or alias is also considered valid here.
  2. J

    "Hijack" other programs stdin & stdout

    I mean literally /dev/tty. This refers to the controlling terminal of the process that opens it.
  3. J

    "Hijack" other programs stdin & stdout

    Am I misunderstanding something or can you just open /dev/tty instead of doing complicated process tree walks?
  4. J

    sh trap handling upon reboot

    Traps are not executed while the shell is waiting for a foreground process to terminate, and a successful reboot(8) never terminates (it eventually calls reboot(2) which does not return control). There is no way to access si_code or any other siginfo_t member in a shell script.
  5. J

    Building the FreeBSD kernel on another OS

    Run make kernel-toolchain or make buildworld first. Otherwise it will try to use the native tools, which will not work from another OS.
  6. J

    SH: Don't know how to refer to this ... :P

    Variables without a $ in arithmetic are documented behaviour (see Arithmetic Expansion in sh(1)) and required by POSIX. Also, variables can be assigned new values. For example, a variable can be incremented without mentioning its name twice: : $((very_long_name += 1)) The ++ and --...
  7. J

    Help with script: DAYOFMONTH=$((`date -j '+%d'`)) fails on 9th of month

    The extra $(( )) may still be useful because it removes the space that %e inserts before days less than 10. The change to 09 is a deliberate change to sh in 9.0.
  8. J

    pts changes

    You are right. This is because utmp was replaced with utmpx and various limits were increased at that time. The limit in 8.x is in the kernel but is only there because of utmp and its importance for tracking sessions.
  9. J

    BUG? -> sh: [ "$@" ] -> "eats" it's quotes!

    [ is expanded like any other simple command. The three tests in your first function are not all expanded the same but all are valid tests returning false. The third test in your second function causes a test(1) syntax error because "$@" expands to nothing at all if there are no positional...
  10. J

    sh -> vars in [ -a ] aren't evalueated correctly

    I recommend not using -a, -o and parentheses at all, but the construct [ ! "$string1" -a "$string2" ] is particularly nasty. Some test implementations such as the builtins in bash and FreeBSD sh consider -a and -o "binary primaries" (POSIX SUSv4 XCU 4 Utilities test) and obey the rule for 4...
  11. J

    64 bit atomic in 32 bit machine

    In the particular case that this 32 bit machine has a Pentium or higher x86 CPU, the CPU provides a 64-bit atomic compare-and-exchange operation CMPXCHG8B. The PAE kernel uses this instruction, see src/sys/i386/include/pmap.h and look for atomic_cmpset_64. This operation is however not generally...
  12. J

    Using tar with wildcards & space in file hierarchy

    The wildcards are expanded by the shell, not ls. Therefore replace things like `ls /var/log/system*` by simply /var/log/system* The shell will not split the results of pathname generation again.
  13. J

    /bin/sh built-in "trap", can't be piped

    Anything can be piped but it will run in a subshell environment so that commands like trap will not print what you may expect. (POSIX allows but does not require this.) In our sh, you can do traps=$(trap) and it will return the parent shell environment's traps; this commonly works but is not...
  14. J

    sh/tcsh and jobs output

    You cannot pipe the output of jobs to something because sh and tcsh always run the left-hand side of a pipe in a subshell environment with its own job list that starts off empty. PR bin/34811 asks for this to be changed in sh but this is unlikely to be in 9.0. In sh you can still get at the...
  15. J

    How to check whether signal handlers remain installed?

    Use sigaction(2) and it is fully defined and portable that the handler remains installed.
  16. J

    IPC: where sem_open() places object name in the actual filesystem

    expl's answer is incorrect, ipcs applies to System V IPC (also called XSI IPC) only, semget/shmget/msgget. For sem_open, the answer depends on the version of FreeBSD (more precisely, the API you compile against, so running on 9.x a binary compiled on 8.x will give the 8.x behaviour). In...
  17. J

    BUG: IFS affects var, during var assignment in 'local'

    Although various shells such as bash, ksh93 and zsh handle this in a more expected manner, FreeBSD sh follows a literal reading of POSIX here. Variable assignments (before a command word or if there is no command word at all) are expanded differently from other words in a simple command...
  18. J

    Pinging a host only while SCP is present

    Traps seem unnecessary here, what you need is sh(1)'s ability to wait for a specific process. For example: scp ... & scppid=$! ping ... & pingpid=$! wait $scppid kill $pingpid wait $pingpid If you combine this with traps, take care that wait terminates prematurely if a trap occurs.
  19. J

    posix message queue question

    Regarding terminology, the API you are asking about is generally known as "System V message queues" or "XSI message queues". "POSIX message queues" use mq_open and related functions. Another option is Unix domain sockets. You are right that the "identifier" is a system-wide number persistent...
  20. J

    IFS goes "right through" double quotes in "${#str}"

    This is now fixed in 9-current (r220903) and 8-stable (r221522).
Back
Top