04-11-2012
Quote:
You have got me curious as it works for me and I thought I had a proper version of sh.
There is almost no such thing as "proper sh". On some systems, sh gets you ksh. On some systems, sh gets you bash. On Solaris, sh gets you something so old and mouldy it's not even POSIX. If you write a plain sh script it should work in almost anything, but it's all too easy to use non-sh features. Frankly, it's tempting, because some of them are just so convenient.
Like the math you've been using, $(( X + 5 )) sort of syntax. That's a bash/ksh thing and not available in pure POSIX bourne shells.
I'd recommend making this script BASH-only anyway, because some of the sector numbers etc. are going to be extremely high numbers, even beyond the 32-bit limit, and the only shell I know of which can tolerate these for integer math is BASH, and only relatively new BASH at that.
Quote:
The string is treated as an expression and so returns false if empty and true otherwise. I am not sure if there is any benefit of the -z and -n tests over this form, but I have always used this way as I find it more readable as it corresponds with other languages.
The benefit is that, if someone plugs strange values into it, it won't blow up or respond inappropriately. Leaving it open-ended like that means could feed something strange into it and cause
syntax errors.
Always tell [ ] what you want to do with the data inside them.
Last edited by Corona688; 04-11-2012 at 01:55 PM..
10 More Discussions You Might Find Interesting
1. Linux
Hi,
I was wondering if any of you guys know of way to make applications that use sound device on linux to access it in a "non-exclusive manner", the aim is to be able to use more than one application that requires the sound device.
Thanks (0 Replies)
Discussion started by: andryk
0 Replies
2. Linux
Hi,
we have running 8 box sles 9 cluster and on an nfs filesystem we have the problem which is grepped from /var/log/messages.
Jun 8 13:40:46 qnclpx02 kernel: attempt to access beyond end of device
Jun 8 13:40:46 qnclpx02 kernel: sdat: rw=0, want=8894615912, limit=314572800
Is there... (1 Reply)
Discussion started by: ortsvorsteher
1 Replies
3. UNIX for Dummies Questions & Answers
Hello everyone,
I write a program (Linux & Solaris) that will run as non-root user, but the program must have rw access to a device /dev/ipmi (on linux) or /dev/bmc (on solaris).
What is the standard way of granting such access?
Linux:
chmod on /dev/ipmi ?
suid root my program?
Solaris:... (1 Reply)
Discussion started by: Pavel.Bures
1 Replies
4. Homework & Coursework Questions
Problem statement.
In this part of the assignment, delegates will create a pseudo-device and write a device driver for it. The pseudo-device provides a “backdoor” for gaining root access for a particular user. Instead of compiling the device driver into the kernel, delegate will create a module.... (1 Reply)
Discussion started by: nyjilgeorge1
1 Replies
5. OS X (Apple)
hi, i am on a quest to access and even mount if possible a drive on os x. there is no driver for the device, but it lists fine in the system profiler. can i access its location from the terminal? how? here is what i get on the system profiler:
Speed: Up to 480 Mb/sec
Manufacturer: SAMSUNG
... (3 Replies)
Discussion started by: sontarieh
3 Replies
6. UNIX for Advanced & Expert Users
I am trying to load into the kernel a system-call dynamically (without restarting the kernel and compailing it) in an attempt to (once in kernel mode) write to user process's memory.
(I know there is a way to do this with the ptrace interface but it is not an option.)
I know the only way to... (1 Reply)
Discussion started by: hopelessProgram
1 Replies
7. Cybersecurity
Equipment: DJI Phantom 3
I have the root and passwords access, but I cannot find out how to access the equipment.
There is a USB port going to a miniUSB that connects to the equipment, but on Windows is detecting the connection as being a Serial Port (COM3).
I need some help in order to gain... (5 Replies)
Discussion started by: nobr3ga
5 Replies
8. Ubuntu
I cannot access or boot from my C drive. I'm running Zorin 9 and the drive is a Samsung SSD. The disk was encrypted on install, and that has not given me any problems before.
When I start the system it gets to the memory test page, and does not then load the password prompt, which it used to.... (1 Reply)
Discussion started by: David4321
1 Replies
9. UNIX for Dummies Questions & Answers
How to provide a client exclusive access to the NTP device or NTP server.
Example:
1. Configured md5 authentication for a subnet added below restriction line to the subnet as below in ntp.conf file. Also configured the keys and md5 authentication working .
restrict 192.168.1.0 mask... (1 Reply)
Discussion started by: iqtan
1 Replies
10. HP-UX
Hi,
Unable to make tape backup, please help.
/opt/ignite/bin/make_tape_recovery -a /dev/rmt/?mn -I -v -m tar -x inc_entire=vg00
* Creating local directories for configuration files and archive.
======= 04/25/16 16:28:08 IST Started /opt/ignite/bin/make_tape_recovery.
(Mon... (4 Replies)
Discussion started by: anuragr
4 Replies
LEARN ABOUT CENTOS
system
SYSTEM(3) Linux Programmer's Manual SYSTEM(3)
NAME
system - execute a shell command
SYNOPSIS
#include <stdlib.h>
int system(const char *command);
DESCRIPTION
system() executes a command specified in command by calling /bin/sh -c command, and returns after the command has been completed. During
execution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT will be ignored.
RETURN VALUE
The value returned is -1 on error (e.g., fork(2) failed), and the return status of the command otherwise. This latter return status is in
the format specified in wait(2). Thus, the exit code of the command will be WEXITSTATUS(status). In case /bin/sh could not be executed,
the exit status will be that of a command that does exit(127).
If the value of command is NULL, system() returns nonzero if the shell is available, and zero if not.
system() does not affect the wait status of any other children.
CONFORMING TO
C89, C99, POSIX.1-2001.
NOTES
If the _XOPEN_SOURCE feature test macro is defined (before including any header files), then the macros described in wait(2) (WEXITSTA-
TUS(), etc.) are made available when including <stdlib.h>.
As mentioned, system() ignores SIGINT and SIGQUIT. This may make programs that call it from a loop uninterruptible, unless they take care
themselves to check the exit status of the child. E.g.
while (something) {
int ret = system("foo");
if (WIFSIGNALED(ret) &&
(WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT))
break;
}
Do not use system() from a program with set-user-ID or set-group-ID privileges, because strange values for some environment variables might
be used to subvert system integrity. Use the exec(3) family of functions instead, but not execlp(3) or execvp(3). system() will not, in
fact, work properly from programs with set-user-ID or set-group-ID privileges on systems on which /bin/sh is bash version 2, since bash 2
drops privileges on startup. (Debian uses a modified bash which does not do this when invoked as sh.)
In versions of glibc before 2.1.3, the check for the availability of /bin/sh was not actually performed if command was NULL; instead it was
always assumed to be available, and system() always returned 1 in this case. Since glibc 2.1.3, this check is performed because, even
though POSIX.1-2001 requires a conforming implementation to provide a shell, that shell may not be available or executable if the calling
program has previously called chroot(2) (which is not specified by POSIX.1-2001).
It is possible for the shell command to return 127, so that code is not a sure indication that the execve(2) call failed.
SEE ALSO
sh(1), signal(2), wait(2), exec(3)
COLOPHON
This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
2010-09-10 SYSTEM(3)