ksh

How to move files from X sub_dir to Y sub_dir

半城伤御伤魂 提交于 2019-12-10 10:14:46
问题 I have main DIR X and inside this I have many sub directories like A,B,C,D. I have main DIR Y and inside this i have many sub directories with same name as X main directory sub directories like A,B,C,D. Now I need to MOVE only files from X main dir sub directories to Y main directory sub directory. Eg: Inside main directory X ,sub directory A has 100 files and B has 1 file and C has 5 files and D has 50 files... my cursor should be at main DIR X , from there I need to MOVE all the sub

Why does ksh allow unpaired quotes while bash does not?

夙愿已清 提交于 2019-12-09 16:06:29
问题 When I execute following command, on bash shell I get error but on Korn shell it runs perfectly fine. The only difference is missing single quote at the end of awk, after }. Could you help me understand why? echo `echo "a b c d" | awk '{ print $1 }` 回答1: In the Korn shell, both back ticks and quotes can be left unmatched, the tokenizer will try and guess where either will end and match them accordingly. Examples: /home/ufierro # echo "`echo ah" + echo ah + echo ah ah /home/ufierro # echo

Shell 高级编程

試著忘記壹切 提交于 2019-12-09 11:23:38
Shell 高级编程 原创 2016-11-04 景峯 Netkiller Shell 高级编程 http://netkiller.github.io/journal/shell.html Mr. Neo Chen (陈景峯), netkiller, BG7NYT 中国广东省深圳市龙华新区民治街道溪山美地 518131 +86 13113668890 <netkiller@msn.com> $Id: shell.xml 449 2012-08-10 10:38:08Z netkiller 版权声明 转载请与作者联系,转载时请务必标明文章原始出处和作者信息及本声明。 Shell 更多是被看成一种批处理命令,确实很多是是吧 Shell当成批处理去使用的。 我确不这么看,我认为要想开发程序一样去写Shell,把Shell当成一种语言。 我们需要将很多软件开发技巧应用在Shell领域 目录 1. 递归调用 2. 实现守护进程 3. 进程间通信 4. 1. 递归调用 不懂递归不算是合格的程序员 递归调用是一种特殊的嵌套调用,是一个函数在它的函数体内调用它自身称为递归调用。这种函数称为递归函数。 #!/bin/bash ######################################## # Author: Neo <netiller@msn.com> # Home : http:

Monitor folder for new files using unix ksh shell script or perl script and trigger perl script

时光毁灭记忆、已成空白 提交于 2019-12-09 09:55:04
问题 I've been Googling and Overflowing for a bit and couldn't find anything usable. I need a script that monitors a public folder and triggers on new file creation and then moves the files to a private location. I have a samba shared folder /exam/ple/ on unix mapped to X:\ on windows. On certain actions, txt files are written to the share. I want to kidnap any txt file that appears in the folder and place it into a private folder /pri/vate on unix. After that file is moved, I want to trigger a

Regarding 'for' loop in KornShell

徘徊边缘 提交于 2019-12-09 03:22:24
问题 Is there a way to implement the following using 'for' in KornShell (ksh)? Here is the C equivalent: for(i=1;i<20;i++) { printf("%d",i); } I was wondering if this can be implemented using just 'for' and not 'while' I tried the following, it does not seem to work. for i in [1-20] do print $i done Please let me know your ideas and solutions. 回答1: Unfortunately, it looks as if ksh does not have support for range-based brace expansion or support the (( )) construct so to do this compactly, you'll

Grep statement in If-Then-Else Statment is not giving intended results

僤鯓⒐⒋嵵緔 提交于 2019-12-08 13:57:42
问题 The intended result of this program is to perform the deletion of a record from a temporary file by searching for the last name. If the name is in the file it will display a message that the record is deleted from the file. The message will have a last and first name of the person deleted. If there is no record for the name entered, display an error message indicating that the name is not in the file. The error message will have the last name of the person searched. For the most part I have

sleep a while loop based on output from a function

梦想与她 提交于 2019-12-08 13:42:31
问题 Need your help with the following. My .sh is as follows. getfunc (){ if [condition 1] then echo "NOK" >flag else echo "OK" >flag fi } while IFS=" " read -r var1 do getfunc if [ $flag -eq OK ] then "print 1" else "sleep for sometime" fi done <file I don't know how to tell while to keep trying in regular intervals, till it gets OK from getfunc. Any help is greatly appreciated. thanks. 回答1: until [[condition]] do echo "sleeping" sleep 5 done 来源: https://stackoverflow.com/questions/47807474/sleep

Shell script to export environment variables in make

折月煮酒 提交于 2019-12-08 09:03:36
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? 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 it to work smoothly on other platforms. Beware, this will probably not work as intended: as each Makefile

A Perl system call must send exactly both characters single & double quote ' "

孤街浪徒 提交于 2019-12-08 06:45:33
问题 A Perl system call must send the following string to the UnixShell : '"XYZ"' In my Perl script I have used the following command: system("cleartool mkattr -replace ATTRIBUTE '"$attribute"' lbtype:$label"); Everything is well passed to the Shell Unix , except both uses of the quote character: ' Indeed, cleartool mkattr -replace ATTRIBUTE The above command is passed as it is exactly what I want. The Perl variables $attribute and $label are well interpreted. But I don't know what to do to obtain

How to get the difference between now and a different date (in minutes) using ksh (or another shell script)?

元气小坏坏 提交于 2019-12-08 06:19:27
问题 Giving two variables with the followind values: date1 = Mon Feb 27 16:21:34 WET 2012 date2 = Mon Feb 27 16:29:34 WET 2012 How can I make the difference (in minutes) between them using ksh? I'm using Solaris 10. I made what you said and this was the error: $ function d { echo $((($(date -d"$2" +%s)-$(date -d"$1" +%s))/60)); } $ d "Mon Feb 27 16:21:34 WET 2012" "Mon Feb 27 16:29:34 WET 2012" date: illegal option -- d date: illegal option -- M date: illegal option -- o date: illegal option -- n