ksh

Why doesn't **sort** sort the same on every machine?

房东的猫 提交于 2019-11-28 01:50:20
Using the same sort command with the same input produces different results on different machines. How do I fix that? The man-page on OS X says: ******* WARNING ******* The locale specified by the environment affects sort order. Set LC_ALL=C to get the traditional sort order that uses native byte values. which might explain things. If some of your systems have no locale support, they would default to that locale (C), so you wouldn't have to set it on those. If you have some that supports locales and want the same behavior, set LC_ALL=C on those systems. That would be the way to have as many

Sub-shell differences between bash and ksh

吃可爱长大的小学妹 提交于 2019-11-28 01:11:43
I always believed that a sub-shell was not a child process, but another shell environment in the same process. I use a basic set of built-ins: (echo "Hello";read) On another terminal: ps -t pts/0 PID TTY TIME CMD 20104 pts/0 00:00:00 ksh So, no child process in kornShell (ksh). Enter bash, it appears to behave differently, given the same command: PID TTY TIME CMD 3458 pts/0 00:00:00 bash 20067 pts/0 00:00:00 bash So, a child process in bash. From reading the man pages for bash, it is obvious that another process is created for a sub-shell, however it fakes $$, which is sneeky. Is this

How to read just a single character in shell script

ⅰ亾dé卋堺 提交于 2019-11-27 23:31:57
I want similar option like getche() in C. How can I read just a single character input from command line? Using read command can we do it? In ksh you can basically do: stty raw REPLY=$(dd bs=1 count=1 2> /dev/null) stty -raw SiegeX In bash, read can do it: read -n1 ans fess . read -n1 works for bash The stty raw mode prevents ctrl-c from working and can get you stuck in an input loop with no way out. Also the man page says stty -raw is not guaranteed to return your terminal to the same state. So, building on dtmilano's answer using stty -icanon -echo avoids those issues. #/bin/ksh ## /bin/{ksh

KSH check if string starts with substring

旧时模样 提交于 2019-11-27 23:25:01
问题 I need to check if the variable has value of string which starts with specified substring. In Python it would be something like this: foo = 'abcdef' if foo.startswith('abc'): print 'Success' What is the most explicit way to check in Ksh whether strig $foo starts with substring bar ? 回答1: It's very simple but looks a bit odd: if [[ "$foo" == abc* ]]; then ... One would assume that ksh would expand the pattern with the files in the current directory but instead, it does pattern matching. You

redirect command output into variable and standard output in ksh

与世无争的帅哥 提交于 2019-11-27 20:31:12
I have some shell command. I would like to write the output to the standard output and save it into variable as well. I'd like to solve it with one command. I have tried these things. ls > $VAR # redirects the output to file which name is stored in $VAR ls | tee -a $VAR # writes to standard output as well as in file which name is stored in $VAR VAR=`ls` # output into $VAR, but it is not sent to standard output VAR=`ls`;echo $VAR # ok, it works but these are two commands Any idea? How about: VAR=$(ls | tee /dev/tty) great answer from @Gary_Barker, but this isn't possible on all systems. On our

Have Find print just the filenames, not full paths

倖福魔咒の 提交于 2019-11-27 20:29:27
问题 I'm using the find command in a ksh script, and I'm trying to retrieve just the filenames, rather than the full path. As in, I want it to return text.exe, not //severname/dir1/dir2/text.exe. How would I go about getting that? To clarify, i know the directory the files are in, i am just grabbing the ones created befoee a ceetain date, so the pathname doesnt matter. 回答1: you can do it with: find ..... |sed 's#.*/##' however does it really make sense? if there are two files with same filename

In a unix shell, how to get yesterday's date into a variable?

只愿长相守 提交于 2019-11-27 18:44:16
I've got a shell script which does the following to store the current day's date in a variable 'dt': date "+%a %d/%m/%Y" | read dt echo ${dt} How would i go about getting yesterdays date into a variable? Basically what i'm trying to achieve is to use grep to pull all of yesterday's lines from a log file, since each line in the log contains the date in "Mon 01/02/2010" format. Thanks a lot If you have Perl available (and your date doesn't have nice features like yesterday ), you can use: pax> date Thu Aug 18 19:29:49 XYZ 2010 pax> dt=$(perl -e 'use POSIX;print strftime "%d/%m/%Y%",localtime

Using sendmail for HTML body and binary attachment

泄露秘密 提交于 2019-11-27 18:00:53
问题 Objective: To send mail (using sendmail) with HTML body and binary attachment. Followed the guidelines specified in the following links http://www.unix.com/shell-programming-scripting/159522-sendmail-html-body-attachment-2.html http://www.unix.com/shell-programming-scripting/58448-sendmail-attachment.html It is working to the extent that, either HTML body or the binary attachment with uuencode, but not both. Given below is a snippet of the shell script to sendmail. With this, the HTML body is

Why does `if $(true) ; then … fi` succeed?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 14:31:55
问题 Inspired by this question: What should an if statement do when the condition is a command substitution where the command produces no output? NOTE: The example is if $(true); then ... , not if true ; then ... For example, given: if $(true) ; then echo yes ; else echo no ; fi I would think that $(true) should be replaced by the output of the true command, which is nothing. It should then be equivalent to either this: if "" ; then echo yes ; else echo no ; fi which prints no because there is no

How to get the second column from command output?

[亡魂溺海] 提交于 2019-11-27 10:46:00
My command's output is something like: 1540 "A B" 6 "C" 119 "D" The first column is always a number, followed by a space, then a double-quoted string. My purpose is to get the second column only, like: "A B" "C" "D" I intended to use <some_command> | awk '{print $2}' to accomplish this. But the question is, some values in the second column contain space(s), which happens to be the default delimiter for awk to separate the fields. Therefore, the output is messed up: "A "C" "D" How do I get the second column's value (with paired quotes) cleanly? Or use sed & regex. <some_command> | sed 's/^.* \(