ksh

Are shell scripts read in their entirety when invoked?

倖福魔咒の 提交于 2019-12-10 19:08:07
问题 I ask because I recently made a change to a KornShell (ksh) script that was executing. A short while after I saved my changes, the executing process failed. Judging from the error message, it looked as though the running process had seen some -- but not all -- of my changes. This strongly suggests that when a shell script is invoked, the entire script is not read into memory. If this conclusion is correct, it suggests that one should avoid making changes to scripts that are running. $ uname

linux + ksh + Round down or Round up - float numbers

こ雲淡風輕ζ 提交于 2019-12-10 17:38:41
问题 in my ksh script I need to calculate only integer numbers Sometimes I get float numbers such as 3.49 or 4.8...etc so I need to translate the float numbers to integer’s numbers according to the following rules (examples) 3.49 will be 3 2.9 will be 3 4.1 will be 4 23.51 will be 24 982.4999 will be 982 10.5 will be 11 ( this example if float is .5 then it will roundup ) Please advice how to do this in ksh or awk or perl Or any other language that can be run in my ksh script 回答1: After a brief

How to detect that foreground process is waiting for input in UNIX?

风流意气都作罢 提交于 2019-12-10 15:59:33
问题 I have to create a script (ksh or perl) that starts certain number of parallel jobs (another scripts), each of them runs as a foreground process in a separate session. Plus I start monitoring job that has to determine if any of those scripts is expecting input from operator, and switch to the corresponding session if necessary. My problem is that I have not found a good way to determine that process is expecting input. For the background process it's pretty easy: process state is "stopped"

Pass wildcard to alias

那年仲夏 提交于 2019-12-10 14:46:04
问题 I use a modifies list command as alias (in KSH): alias ltf='ls -lrt -d -1 $PWD/*' So the command ltf displays something like this: -rw-r--r-- 1 myuser mygroup 0 Apr 18 12:00 /usr/test.txt -rw-r--r-- 1 myuser mygroup 0 Apr 18 12:00 /usr/test.log Now I want to use wildcards. But using ltf *.log does not work. What is the best way to achieve that? Update: I want to specify my question because the answers does not solve my problem so far: the command ls -lrt -d -1 $PWD/* executes a list command

Why shouldn't I “bet the future of the company” on shell scripts? [closed]

妖精的绣舞 提交于 2019-12-10 14:34:29
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . I was looking at http://tldp.org/LDP/abs/html/why-shell.html and was struck by: When not to use shell scripts ... Mission-critical applications upon which you are betting the future of the company Why not? 回答1: Using shell scripts is fine when you're using their strengths. My

ksh associate array

佐手、 提交于 2019-12-10 14:18:16
问题 I have a script that needs to use associative arrays. Being new to ksh, I am unable to find anywhere that ksh supports associative arrays. When I try to use regular array syntax and assign, I get an error that index cannot be that big. Does ksh support associative arrays? If not, what is the alternative solution? need to do the following: ${array[$name]}=value and later in the code, I need to read value for ${array[$name]}. I have about 2000 values to be stored and read from the array

How do I read a value from user input into a variable

我是研究僧i 提交于 2019-12-10 13:13:26
问题 In ksh, how do I prompt a user to enter a value, and load that value into a variable within the script? command line echo Please enter your name: within the script $myName = ? 回答1: You want read: echo Please enter your name: read name echo $name See read(1) for more. 回答2: You can do it in a single line, like so: read -p "Please enter your name:" myName To use variable in script echo "The name you inputed is: $myName" echo $myName 来源: https://stackoverflow.com/questions/6802848/how-do-i-read-a

Extract data from XML using ksh script

北城余情 提交于 2019-12-10 12:05:02
问题 The first question I asked on this topic was closed because of lack of info. So asking this again with some more details added. I have to extract a value given in one tag from a xml file and I have to do it using ksh (I can solve this in perl but I have to do it ksh, cannot use third party tools like xmlsh) sample.xml <?xml version="1.0" standalone="yes" ?> <parent_one> <parent_two> <Pool> <pool_name>ABC</pool_name> <percent_full>79</percent_full> <pool_state>Enabled</pool_state> </Pool>

KornShell equivalant of PIPESTATUS

会有一股神秘感。 提交于 2019-12-10 11:53:14
问题 . ${script_name} | tee -a ${log_file} KornShell unfortunately does not have a PIPESTATUS command like Bash does and I would like to know if anybody has an elegant solution to getting the exit status of the first command (above). This is what I've pieced together from code found around the internets. { typeset -r script_rc=$( { { . ${script_name} echo "$?" >&3 } | tee -a ${log_file} } 3>&1 >&4 4>&- ) } 4>&1 Unfortunately this code is hard to read and I was wondering if someone knew of

Shell script to export environment variables in make

微笑、不失礼 提交于 2019-12-10 11:45:52
问题 I want to use a ksh script to set up some environment variables that my makefile will later use. I tried to do: setup: . myscript But it gives me errors like [[: not found . Is there a way to use an external script to load environment variables for make? 回答1: You could change the shell used in the makefile: SHELL = /usr/bin/ksh # Or whatever path it's at But it's probably a good idea to convert the script to something compatible with /bin/sh (ideally completely POSIX-compatible) if you want