ksh

set -e and short tests

╄→гoц情女王★ 提交于 2019-11-29 20:52:19
When I was new to shell scripting, I used a lot of short tests instead of if statements, like false && true . Then later I learned using set -e , and found my scripts were dying for some reason, and they would work if I replaced the short tests with full if statements. Now, the time has gone, and I still use full if statements only. The most interesting is that if I open an interactive shell and do the following: set -e false && true echo $? it returns 1 but the shell doesn't die! I see that I have been wasting too many lines of code. Anyone could explain to me how can I use set -e with short

Android adb shell - ash or ksh?

丶灬走出姿态 提交于 2019-11-29 13:06:19
问题 The Android online documentation Android Debug Bridge says "Adb provides an ash shell". Sure enough, if I adb shell to an AVD emulator I get ash which is basically a cut-down Bourne shell. However, if I connect to a couple of remote devices, one an HTC telephone and the other an ASUS Transformer Prime tablet, they both have a version of the Korn shell, which gives: KSH_VERSION='@(#)MIRBSD KSH R39 2010/08/24' . Although MIRBSD KSH is not a full-blown AT&T Korn shell, it is still a lot more

sed -i touching files that it doesn't change

拥有回忆 提交于 2019-11-29 10:47:05
Someone on our server ran sed -i 's/$var >> $var2/$var > $var2/ * to change inserts to overwrites in some bash scripts in a common directory. No big deal, it was tested first with grep and it returned the expected results that only his files would be touched. He ran the script and now 1200 files of the 1400 in the folder have a new modified date, yet as far as we can tell, only his small handful of files were actually changed. Why would sed 'touch' a file that it's not changing. Why would it only 'touch' a portion of the files and not all of them. Did it actually change something (maybe some

Scope of variables in KSH

不羁的心 提交于 2019-11-29 08:18:52
问题 I have written a sample KornShell function to split a String, put it in an array and then print out the values. The code is as below #!/usr/bin/ksh splitString() { string="abc@hotmail.com;xyz@gmail.com;uvw@yahoo.com" oIFS="$IFS"; IFS=';' set -A str $string IFS="$oIFS" } splitString echo "strings count = ${#str[@]}" echo "first : ${str[0]}"; echo "second: ${str[1]}"; echo "third : ${str[2]}"; Now the echo does not print out the values of the array, so I assume it has something to do with the

Using sendmail for HTML body and binary attachment

风格不统一 提交于 2019-11-29 03:57:41
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 coming fine, but the attachment is getting encoded/decoded wrongly and unable to view the same. Please

how to SSH Login Without Password [closed]

蓝咒 提交于 2019-11-29 01:14:01
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . To use sftp in a script without user interaction (non-interactive). For example to login to an anonymous ftp server and not have to manually. 回答1: On your computer cd ~/.ssh ssh-keygen -t dsa press the enter key at every prompt Generating public/private dsa key pair. Enter file in which to save the key (/home

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

情到浓时终转凉″ 提交于 2019-11-28 23:05: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 command whose name is the empty string, or to this: if ; then echo yes ; else echo no ; fi which is a

How to set the From email address for mailx command?

China☆狼群 提交于 2019-11-28 20:53:09
问题 I am working on a KornShell (ksh) script running on a Solaris server that will send out an email when and error condition is met. I am sending the email via mailx . Question: How do I set the "From" email address on the mailx command? Current Code: echo ${msg_txt} | mailx -s "Script Failure" ${to_email} Note: The command works fine, however, the "From" is the name of the user I am running the script as and I would like for this to another email address. How would I accomplish this? 回答1: You

How do I recursively list all directories at a location, breadth-first?

二次信任 提交于 2019-11-28 18:46:35
问题 Breadth-first list is important, here. Also, limiting the depth searched would be nice. $ find . -type d /foo /foo/subfoo /foo/subfoo/subsub /foo/subfoo/subsub/subsubsub /bar /bar/subbar $ find . -type d -depth /foo/subfoo/subsub/subsubsub /foo/subfoo/subsub /foo/subfoo /foo /bar/subbar /bar $ < what goes here? > /foo /bar /foo/subfoo /bar/subbar /foo/subfoo/subsub /foo/subfoo/subsub/subsubsub I'd like to do this using a bash one-liner, if possible. If there were a javascript-shell, I'd

Make Arrow and delete keys work in KornShell command line

℡╲_俬逩灬. 提交于 2019-11-28 17:36:40
I am new to Unix and am using sun solaris (v10 I think). I have my shell set as KornShell (ksh). I am wondering how to make the arrow keys and delete key work in the command line. I have done set -o emacs and the backspace works, but not the arrow keys and the delete keys. Also is it possible to set the up and down arrow key to cycle through the command line history? For the arrow keys, you can put this into your the .kshrc file in your home directory: set -o emacs alias __A=`echo "\020"` # up arrow = ^p = back a command alias __B=`echo "\016"` # down arrow = ^n = down a command alias __C=