ksh

Grab the filename in Unix out of full path

若如初见. 提交于 2019-12-18 12:03:39
问题 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? 回答1: 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##*/} 回答2: basename path gives the file name at the end of path Edit: It is probably worth adding that a common

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

流过昼夜 提交于 2019-12-18 11:49:42
问题 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, 回答1: 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,

set -e and short tests

跟風遠走 提交于 2019-12-18 10:14:16
问题 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

sed -i touching files that it doesn't change

早过忘川 提交于 2019-12-18 06:06:45
问题 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

Pipe input into a script

若如初见. 提交于 2019-12-17 22:34:22
问题 I have written a shell script in ksh to convert a CSV file into Spreadsheet XML file. It takes an existing CSV file (the path to which is a variable in the script), and then creates a new output file .xls. The script has no positional parameters. The file name of the CSV is currently hardcoded into the script. I would like to amend the script so it can take the input CSV data from a pipe, and so that the .xls output data can also be piped or redirected (>) to a file on the command line. How

Sub-shell differences between bash and ksh

自作多情 提交于 2019-12-17 16:48:34
问题 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

How to get the second column from command output?

给你一囗甜甜゛ 提交于 2019-12-17 07:07:29
问题 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

Wait (the end of N process in ksh and after run another process) dont work correctly

馋奶兔 提交于 2019-12-14 04:27:17
问题 my script is: #!/bin/ksh WORKFLOW1=wf_m_LOAD_ODS_DMT_FATTO_E_BSN_LETTURE_F WORKFLOW2=wf_m_LOAD_ODS_DMT_FATTO_E_ANAGRAFICA_POD_F WORKFLOW3=wf_m_LOAD_ODS_DMT_FATTI_E_QF_F pmcmd startworkflow -sv $SERVER -d $DOMINIO -u $USER -p $PASSWD -f $DIRECTORY_SEC_LEV_ELE $WORKFLOW1 & pmcmd startworkflow -sv $SERVER -d $DOMINIO -u $USER -p $PASSWD -f $DIRECTORY_SEC_LEV_ELE $WORKFLOW2 & pmcmd startworkflow -sv $SERVER -d $DOMINIO -u $USER -p $PASSWD -f $DIRECTORY_SEC_LEV_ELE $WORKFLOW3 &; wait; echo "Lancio

With ksh93, how to safely init a 2-dimensioned indexed array to ( () )

妖精的绣舞 提交于 2019-12-13 18:19:23
问题 With ksh93, typeset -a arr=( () ) will create arr[0] as an empty compound var rather than an empty indexed array: $ typeset -a arr=( () ) $ typeset -p arr[0] typeset -C arr[0]=() $ So how can I init arr[0] to an empty indexed array when declaring the arr var? 回答1: $ ( typeset -a a[0]=(); typeset -p a 'a[0]' ) typeset -a a=( () ) typeset -a a[0] I don't think anybody knows for sure. I asked whether someone could explain some of the logic behind ksh's seemingly random declarations in your

sed command not accepting sub-string with '.' in ksh

落花浮王杯 提交于 2019-12-13 08:58:48
问题 I am writing a ksh script which processes a path variable containing @sys substring to its corresponding OS name: If build_type is is of 64bit version we need to append .64 at the end of osver . e.g. if opsys=amd64_linux26_rh5 (Red Hat Enterprise Linux 5) and build_type=dbg64 , osver should be amd64_linux26_rh5.64 . Now, I want to replace @sys present in file_path variable with its corresponding OS version as a substring i.e. amd64_linux26_rh5.64 . But it looks like sed is ignoring . somehow