bash

Rename files using bash/regex?

旧城冷巷雨未停 提交于 2021-02-05 07:33:13
问题 I have files named: test-12.5.0_567-release.apk I want them to look like: test-release.apk I realized I can do it with bash: for file in *release.apk; do mv "$file" "`basename $file SOMETHING`NEW_FILE_NAME"; done It needs some regex I guess ? How would it look like ? Thanks ! 回答1: You can do: for file in *release.apk; do mv "$file" "${file/-*-/-}" done 回答2: Alternatively you can use this: for file in *release.apk; do mv "$file" "${file%-*-*}-release.apk" I'm removing -12.5.0_567-release.apk

uniq + not get uniq strings from file

◇◆丶佛笑我妖孽 提交于 2021-02-05 07:29:04
问题 Please take a look on the following all I want is to get the node_name string from the file and perform uniq to get uniq strings if they equal but on the following example I have two equal lines ( node_name moon1 ) but why uniq command not decrease it to one line??? , I am really not understand this why? sed s'/=/ /'g file| awk -v WORD=node_name '$2 == WORD {print $0}' | awk '{print $2" "$3}' | sort | uniq node_name moon1 node_name moon1 the file: . . /home/home1/home2/config1/COMPANY/my

FTP delete directories older than X days

旧时模样 提交于 2021-02-05 07:22:47
问题 I'm creating a script based on this one. But when i run it on the results it's deleting files newer than tha date if the months aren't the same. Linux shell script for delete old files from ftp "Removing 02-02-2015" which is a backup i created today #!/bin/bash # get a list of directories and dates from ftp and remove directories older than ndays ftpsite="hostname" ftpuser="user" ftppass="pass" putdir="/full" ndays=15 # work out our cutoff date MM=`date --date="$ndays days ago" +%b` DD=`date

FTP delete directories older than X days

纵然是瞬间 提交于 2021-02-05 07:22:25
问题 I'm creating a script based on this one. But when i run it on the results it's deleting files newer than tha date if the months aren't the same. Linux shell script for delete old files from ftp "Removing 02-02-2015" which is a backup i created today #!/bin/bash # get a list of directories and dates from ftp and remove directories older than ndays ftpsite="hostname" ftpuser="user" ftppass="pass" putdir="/full" ndays=15 # work out our cutoff date MM=`date --date="$ndays days ago" +%b` DD=`date

Log in to Heroku via bash script

丶灬走出姿态 提交于 2021-02-05 07:15:47
问题 I try to write a script in which I call some command from heroku toolbelt. Script works fine till I am login to heroku toolbelt. When I've tried to add heroku's login command during script execution I occured some problems - there is no in heroku toolbelt command such as (command with parameters): heroku login -u email@mail.com -p 1234qwer That why I have no idea how to execute heroku login command in bash script. Has anyone got some advice? 回答1: For these kinds of things I use expect. You

Log in to Heroku via bash script

佐手、 提交于 2021-02-05 07:15:16
问题 I try to write a script in which I call some command from heroku toolbelt. Script works fine till I am login to heroku toolbelt. When I've tried to add heroku's login command during script execution I occured some problems - there is no in heroku toolbelt command such as (command with parameters): heroku login -u email@mail.com -p 1234qwer That why I have no idea how to execute heroku login command in bash script. Has anyone got some advice? 回答1: For these kinds of things I use expect. You

Why does my script suddenly exit after a command?

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-05 07:12:08
问题 I am trying to generate docsets for Dash following these instructions: http://kapeli.com/docsets. The problem is, that the script doesn't continue after the wget and doesn't appear to throw any errors. Everything works fine when I copy the script into the Terminal. I'm using MacOS 10.8.4 and the default bash. #!/usr/bin/env bash set -e mkdir -p $1.docset/Contents/Resources/Documents/ echo "THIS RUNS" wget -rkp -l3 -np -nH --cut-dirs=1 --directory-prefix="./"$1".docset/Contents/Resources

Why does my script suddenly exit after a command?

泄露秘密 提交于 2021-02-05 07:11:06
问题 I am trying to generate docsets for Dash following these instructions: http://kapeli.com/docsets. The problem is, that the script doesn't continue after the wget and doesn't appear to throw any errors. Everything works fine when I copy the script into the Terminal. I'm using MacOS 10.8.4 and the default bash. #!/usr/bin/env bash set -e mkdir -p $1.docset/Contents/Resources/Documents/ echo "THIS RUNS" wget -rkp -l3 -np -nH --cut-dirs=1 --directory-prefix="./"$1".docset/Contents/Resources

Why does Bash with -e option exit when 'let' expression evaluates to 0? [duplicate]

廉价感情. 提交于 2021-02-05 06:49:06
问题 This question already has answers here : bash set -e and i=0;let i++ do not agree (3 answers) Closed 5 years ago . I am struggling to understand why the bash -e option exits this script. It happens only when the expression calculated gives 0 : #!/bin/bash set -ex table_year=( 1979 1982 1980 1993 1995 ) year=$1 let indice=year-1 real_year=${table_year[$indice]} echo OK $real_year Is is ok when: ./bash_test_array 2 but not when: ./bash_test_array 1 indice is this case equals to 0 . Why the -e

Bash and jq nested loops on json

纵然是瞬间 提交于 2021-02-05 06:47:25
问题 I try to use jq to parse a json file and use it in a bash script, but i'm having some difficulties. The json [ {"annonce_id":"123","photos":["url_01"],"titre_slug":"slug1"}, {"annonce_id":"456","photos":["url_11","url_12"],"titre_slug":"slug2"}, {"annonce_id":"7890","photos":["url_31"],"titre_slug":"slug3"}, {"annonce_id":"1234","photos":["url_41"],"titre_slug":"slug4"}, {"annonce_id":"5678","photos":["url_51"],"titre_slug":"slug5"}, {"annonce_id":"90123","photos":["url_61"],"titre_slug":