ksh

Select unique or distinct values from a list in UNIX shell script

*爱你&永不变心* 提交于 2019-11-30 10:04:47
问题 I have a ksh script that returns a long list of values, newline separated, and I want to see only the unique/distinct values. It is possible to do this? For example, say my output is file suffixes in a directory: tar gz java gz java tar class class I want to see a list like: tar gz java class 回答1: You might want to look at the uniq and sort applications. ./yourscript.ksh | sort | uniq (FYI, yes, the sort is necessary in this command line, uniq only strips duplicate lines that are immediately

Android adb shell - ash or ksh?

最后都变了- 提交于 2019-11-30 09:13:08
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 powerful than ash. The emulator is running Jelly Bean, and both devices are using ICS. Doing a bit more

Regex in KornShell

末鹿安然 提交于 2019-11-30 09:02:21
I am trying to check whether a variable is exactly two numbers but I can not seem to figure it out. How do you do check regular expressions (regex) in KornShell (ksh)? I have tried: if [[ $month =~ "[0-9]{2}" ]] if [[ $month = _[0-9]{2}_ ]] I have not been able to find any docs on it. Any insight? case $month in [0-9][0-9]) echo "ok";; *) echo "no";; esac should work. If you need full regexp search, you can use egrep like this: if echo $month | egrep -q '^[0-9]{2}$' then echo "ok" else echo "no" fi Ksh has supported limited extended patterns since ksh88, using the special '(' pattern ')'

How do you use ssh in a shell script?

扶醉桌前 提交于 2019-11-30 06:54:04
When I try to use an ssh command in a shell script, the command just sits there. Do you have an example of how to use ssh in a shell script? Depends on what you want to do, and how you use it. If you just want to execute a command remotely and safely on another machine, just use ssh user@host command for example ssh user@host ls In order to do this safely you need to either ask the user for the password during runtime, or set up keys on the remote host. Jon Ericson First, you need to make sure you've set up password-less (public key login). There are at least two flavors of ssh with slightly

How can I have term.el (ansi-term) track directories if using anyhting other than bash

梦想与她 提交于 2019-11-30 05:40:59
问题 When using eshell or ansi-term and bash emacs changes the default-directory variable depending on what directory you are in. So if I move to /home/user/code/project and then use ido-find-file to open a file it starts ido with the CWD. If I use ksh (my normal shell) or zsh (tried for testing) it doesnt work. Is there a setting or is this just supported under bash? Thanks 回答1: Put this in your .zshrc: chpwd() { print -P "\033AnSiTc %d" } print -P "\033AnSiTu %n" print -P "\033AnSiTc %d" The

Grab the filename in Unix out of full path

你。 提交于 2019-11-30 05:36:30
I am trying to get "abc.txt" out of /this/is/could/be/any/path/abc.txt using Unix command. Note that /this/is/could/be/any/path is dynamic. Any idea? Thanks in advance. kev In bash : path=/this/is/could/be/any/path/abc.txt If your path has spaces in it, wrap it in " path="/this/is/could/be/any/path/a b c.txt" Then to extract the path, use the basename function file=$(basename "$path") or file=${path##*/} basename path gives the file name at the end of path Edit: It is probably worth adding that a common pattern is to use back quotes around commands e.g. `basename ...`, so UNIX shells will

Can I get the absolute path to the current script in KornShell?

醉酒当歌 提交于 2019-11-30 04:42:10
Is it possible to find out the full path to the script that is currently executing in KornShell (ksh)? i.e. if my script is in /opt/scripts/myscript.ksh , can I programmatically inside that script discover /opt/scripts/myscript.ksh ? Thanks, Marnix You could use: ## __SCRIPTNAME - name of the script without the path ## typeset -r __SCRIPTNAME="${0##*/}" ## __SCRIPTDIR - path of the script (as entered by the user!) ## __SCRIPTDIR="${0%/*}" ## __REAL_SCRIPTDIR - path of the script (real path, maybe a link) ## __REAL_SCRIPTDIR=$( cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P ) In

how to SSH Login Without Password [closed]

我的未来我决定 提交于 2019-11-30 04:06:02
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. E.G. 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/user/.ssh/id_dsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/user/.ssh/id_dsa. Your public key has been saved in /home/user/.ssh/id_dsa.pub. The key fingerprint is: ad:98:43:13:c9:ea:66:8e:d0:d9:66:59:d8:3a:f7:29

Have Find print just the filenames, not full paths

。_饼干妹妹 提交于 2019-11-30 01:56:06
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. Kent you can do it with: find ..... |sed 's#.*/##' however does it really make sense? if there are two files with same filename but located in different directories, how can you distinguish them? e.g. you are in /foo /foo/a.txt /foo

How to set the From email address for mailx command?

て烟熏妆下的殇ゞ 提交于 2019-11-29 23:44:56
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? You can use the "-r" option to set the sender address: mailx -r me@example.com -s ... The "-r" option is invalid