sh

Current Directory in Shell Script

吃可爱长大的小学妹 提交于 2019-12-13 19:26:31
问题 I am quite new to shell scripting. I am trying to make a directory when a user runs my script using bash scriptName.sh . At present my shell script looks like, mkdir -p build/iphoneos/XXXXXXXXXX.txt I want to know how I can put the current directory's name in place of XXXXXXX , in the script. Any help will be appreciated. 回答1: You could use: mkdir -p build/iphoneos/$(basename $PWD).txt or mkdir -p build/iphoneos/${PWD##*/}.txt The first calls the basename binary. The second one removes all

Bash - Read HTML & find div based on two different variables

落花浮王杯 提交于 2019-12-13 17:35:57
问题 I am trying to get information from a div based on a date that I am holding as a variable, then I am trying to filter the returned results based on another variable to narrow down the results list to a single match in order to extract the URL. Example of the HTML of the page, this will have another 10 items with the information being different. The same date may appear more than once.. <div class="bhangra-artist details "> <div class="bhangra-artist card"> <div class="bhangra-artist-title"

POSIX Shell backslash confusion

随声附和 提交于 2019-12-13 15:13:42
问题 I am trying to create a shell script with a simple functionality, but it seems I can not wrap my head about how to handle backslashes correctly. One of my functions look like this: #!/bin/sh func() { cmd="$*" printf "%s\n" "$cmd" echo -e $cmd } func '%{NAME}\\n' This is the correct output, as I need it: %{NAME}\\n %{NAME}\n Now the problem is, I can not use "echo -e", as this script needs to be run on *nix system, where the echo command does not have the "-e" flag (HPUX for instance), that

“if” statement won't work on Debian Linux

微笑、不失礼 提交于 2019-12-13 14:43:27
问题 I have a bash script which contains the following "if" statement. The problem is I can't get it to run on Debian (it runs fine on Fedora and CentOS). if [ $1 == "--daily" ] # <--- line 116 then countDaily elif [ $1 == "--monthly" ] # <--- line 119 then countMonthly fi after running it: sh /home/kris/countsc.sh --daily I'm getting an error: /home/kris/countsc.sh: 116: [: --daily: unexpected operator /home/kris/countsc.sh: 119: [: --daily: unexpected operator 回答1: Since you are using sh , and

Syntax error: Bad for loop variable

瘦欲@ 提交于 2019-12-13 13:14:46
问题 I'm trying to write a script that will vol up radio in the background #!/bin/sh for (( i = 80 ; i <= 101; i++ )) do amixer cset numid=1 i$% sleep 60; done But i have problem: alarmclock-vol.sh: 3: alarmclock-vol.sh: Syntax error: Bad for loop variable 回答1: The for (( expr ; expr ; expr )) syntax is not available in sh . Switch to bash or ksh93 if you want to use that syntax. Otherwise, the equivalent for sh is: #!/bin/sh i=80 while [ "$i" -le 101 ]; do amixer cset numid=1 "$i%" sleep 60 i=$((

How to get all process ids with memory usage greater than

北战南征 提交于 2019-12-13 11:26:45
问题 I need to get all process ids which have memory usage greater or lower than predifined number. For example get id where memory (rss) usage grater than 10MB and then using this id kill each process. Thanks 回答1: This following command will help I think, ps aux --sort -rss Try it. 回答2: That's not a good idea. You will certainly kill processes you should not and might render your system damaged in the process. But anyway, here's what does the trick: ps -eo rss=,pid=,user=,comm= k -rss | while

Unix - How to find what place a word comes in a sentence

只谈情不闲聊 提交于 2019-12-13 08:39:58
问题 Basically, I'm writing a shell script in Unix and I need to retrieve a value that says what place a word occurs in a sentence/string and then store that value in a variable. For example, the word "blue" is the third word in the following sentence "the fast blue car". Therefore, I'd like the value for this word to be 3 and store it in a variable called $blue. I.e. echo $blue would print out the number 3. All the examples I've found so far print out the position of a word in terms of characters

How to write file creation script? [closed]

雨燕双飞 提交于 2019-12-13 08:14:21
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . I am very new to scripting and would like to know how to write a script fileCreate which has two optional parameters two input arguments as shown below: fileCreate <filename> <path> <filename> parameter signifies the name of the file in which the contents will be saved <path>

sed in AIX script do not work with special chars [duplicate]

帅比萌擦擦* 提交于 2019-12-13 06:30:58
问题 This question already has answers here : How to use a bash script variable with sed [duplicate] (3 answers) sed substitution with bash variables (4 answers) Closed 3 years ago . I created a script that is generating HTML code. At the end of the script, I need to hightlight some words in a table by making them bold. So I need to replace in the code, every instance of WORD by WORD or WORD of course, WORD is stored in a variable $CODE to make this much more harder. I tryed to used the sed

Checking whether a variable set by the parent exists

梦想与她 提交于 2019-12-13 06:30:21
问题 Suppose the following Makefile (see here what it's good for): target-1-raw: target-1-body target-2-raw: target-2-body target-3-raw: target-3-body %-raw: echo "Error: Target $@ does not exist!" %: @$(MAKE) $@-raw 3>&2 2>&1 1>&3 I am trying to make sure that the user invoked it without the suffix -raw , i.e. like this: make target-1 and not like this: make target-1-raw So, I would like to set a variable in the rule of the target % and check from all other targets that this variable was set: