sh

Trailing arguments with find -exec {} +

我是研究僧i 提交于 2019-12-02 18:31:20
问题 I want to add a trailing argument to the appending version of the -exec option of find . find . -exec echo {} asd + # expecting the following output: file1 file2 file3 [...] asd Does not work as {} must be the last word before + . (Bonus question: Why was that trivial looking feature not implemented?) What is the simplest expression to archive this, that can handle filenames with spaces and special characters? POSIX conformance would be a nice to have but it is sufficient if it works with

How to show wget progress bar only?

删除回忆录丶 提交于 2019-12-02 17:24:20
For example: wget http://somesite.com/TheFile.jpeg downloading: TheFile.tar.gz ... --09:30:42-- http://somesite.com/TheFile.jpeg => `/home/me/Downloads/TheFile.jpeg' Resolving somesite.co... xxx.xxx.xxx.xxx. Connecting to somesite.co|xxx.xxx.xxx.xxx|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 1,614,820 (1.5M) [image/jpeg] 25% [======> ] 614,424 173.62K/s ETA 00:14 How can i get it to look like this downloading: TheFile.jpeg ... 25% [======> ] 614,424 173.62K/s ETA 00:14 I know curl can do that, however i need to get wget to do that job. You can use the following

Bourne shell - make a loop for each element in an array?

为君一笑 提交于 2019-12-02 17:20:00
问题 This is my array: ListTabs="" ListTabs=$ListTabs"T_Tab1\n" ListTabs=$ListTabs"T_Tab2\n" ListTabs=$ListTabs"T_Tab3" echo $ListTabs arrArr=0 OLD_IFS=$IFS; IFS=\n for listArr in ${ListTabs[@]}; do #echo $listArr MYDIR[${ARR}]=$listArr (( arrIdx = $ARR+ 1 )) done IFS=$OLD_IFS; then, i have done a sort of id from a select in this way (FILESELECT_DAT is a output file of query): sort -u ${FILESELECT_DAT} > ${SORT_OUT1} ok..Now i have to make a loop that for each element of array makes a SELECT where

定时任务解决tomcat日记catalina.out分割备份

无人久伴 提交于 2019-12-02 17:13:20
vi bakup.sh 内容如下: cp -rf /var/tomcat6/logs/catalina.out /var/tomcat6/logs/catalina.`date +%Y-%m-%d`.log echo > /var/tomcat6/logs/catalina.out 保存 设置crontab,每天定时切割 首先需要确定你的服务器有没有安装crontab的服务,输入crontab -e命令,有反应就安装了。 如果没有安装,运行yum install vixie-cron 一键安装。 输入crontab -e命令,输入下面的内容: 1、00 00意思为00分00点,也就是凌晨0点,后面“ * * * ”为“ 日 月 年 ”无需定义 2、” /var/tomcat6/logs/backup.sh “为你的shell的路径。 59 23 * * * /var/tomcat6/logs/backup.sh OK ! 大功告成, 指定每天的深夜11点59分的时候进行一次备份。也就是触发那个sh的运行。 $ service crond restart // 重启服务 backup.sh 示例 #!/bin/bash log_path=/data/tomcat-jwifi/logs d=`date +%Y-%m-%d` d7=`date -d'7 day ago' +%Y-%m-

Return a regex match in a BASH script, instead of replacing it

冷暖自知 提交于 2019-12-02 17:12:04
I just want to match some text in a BASH script, i’v tried using sed, but I can’t seem to make it just output the match instead of replacing it with something. echo -E "TestT100String" | sed 's/[0-9]+/dontReplace/g' Which will output: TestTdontReplaceString Which isn’t what I want, I want it to output: 100 Ideally I would want it to put all the matches in an array. edit: Text input is coming in as a string: newName() { #Get input from function newNameTXT="$1" if [[ $newNameTXT ]]; then #Use code that im working on now, using the $newNameTXT string. fi } echo "TestT100String" | sed 's/[^0-9]*\(

How to solve “bad interpreter: No such file or directory”

。_饼干妹妹 提交于 2019-12-02 17:03:42
I'm trying to run a sh script and get the following error on Mac: /usr/bin/perl^M: bad interpreter: No such file or directory How can I fix this? Remove ^M control chars with perl -i -pe 'y|\r||d' script.pl sergio /usr/bin/perl^M: Remove the ^M at the end of usr/bin/perl from the #! line at the beginning of the script. That is a spurious ASCII 13 character that is making the shell go crazy. Possibly you would need to inspect the file with a binary editor if you do not see the character. You could do like this to convert the file to Mac line-ending format: $ vi your_script.sh once in vi type:

g++ command line macro define byte stream

自闭症网瘾萝莉.ら 提交于 2019-12-02 15:47:51
问题 I'm looking for the solution to define a byte stream as a macro from gcc/g++ command line via option -D, e.g. -Dxxx=byte_stream. Below is the code snippet, #ifndef MAGIC_BYTES #define MAGIC_BYTES "\x01\x02\x00\x00\xa0\xb0" #endif I wish every time I can recompile the code without editing the source but using -DMAGIC_BYTES=xxx to define the byte stream. I know to edit the source could be the solution, but just wonder how to define such byte stream from command line. UPDATE, I put the simple

What is sudo bang bang? [closed]

痴心易碎 提交于 2019-12-02 14:48:01
Besides from this comic, I have seen some people write sudo !! . What is sudo bang bang? The bang bang ( !! ) command is a shortcut to repeat the previous command you entered in your terminal . This command is very useful when you forget that you need admin rights to make a certain action, and lets you repeat it with super-user rights just by typing sudo !! instead of typing arrow-up, scrolling to the beginning of the line, adding sudo and hitting enter (imagine scrolling through those loooong apt-get commands). So many seconds gained! Yay! There are many other bang-commands such as !x , !?x ,

Get specific line from text file using just shell script

喜夏-厌秋 提交于 2019-12-02 14:05:59
I am trying to get a specific line from a text file. So far, online I have only seen stuff like sed, (I can only use the sh -not bash or sed or anything like that). I need to do this only using a basic shell script. cat file | while read line do #do something done I know how to iterate through lines, as shown above, but what if I just need to get the contents of a particular line sed: sed '5!d' file awk: awk 'NR==5' file micromoses Assuming line is a variable which holds your required line number, if you can use head and tail , then it is quite simple: head -n $line file | tail -1 If not, this

Shell line 7: [14: command not found [duplicate]

限于喜欢 提交于 2019-12-02 13:27:47
This question already has an answer here: shell script command not found when comparing string 1 answer I don't know what is the problem to fix Here is the code: #!/bin/sh while true do HOUR=$(date '+%H') TARGET=16 echo $HOUR if [$HOUR -gt $TARGET]; then mail -s "IP" "example@hotmail.com" <<EOF Global_IP=$(curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//') EOF echo "Sent" fi echo "Waiting..." sleep 3600 echo "Done waiting" done Please help! You have to add blanks after [ and before ] : if [ $HOUR -gt $TARGET ]; 来源: https://stackoverflow.com/questions/34809142/shell