Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

learn more… | top users | synonyms (1)

1
vote
1answer
193 views

curl and grep commands output into a new variable

I am extracting information from a website. I designed the code in VBA and found that it is taking too long to execute. So, I have decided to rewrite the code in Unix script. I am extracting a page ...
2
votes
2answers
63 views

How to add an audio file to a shell script

How can I add an audio file (OGG vorbis) into a shell script making the script as small as possible and at the same time being able to execute it on as most systems as possible? I want the audio file ...
5
votes
2answers
106 views

Cache all gpg subkey passwords at once? Prevent need for multiple gpg password entry?

Can I enter my gpg password just once and unlock all my sub keys (signing, decryption, authentication)? At the moment, I need to enter my gpg password three times (for signing, for decryption, for ...
2
votes
2answers
172 views

Do I need to encapsulate awk variables in quotes in order to sanitize them?

As per an answer on stackoverflow, it's my understanding that encapsulating bash variables in double-quotes is a fairly safe way of sanitizing user input. What about awk variables? For example, if ...
3
votes
2answers
96 views

Add thousands separator in a number

In python re.sub(r"(?<=.)(?=(?:...)+$)", ",", stroke ) To split a number by triplets, e.g.: echo 123456789 | python -c 'import sys;import re; print re.sub(r"(?<=.)(?=(?:...)+$)", ",", ...
4
votes
2answers
116 views

run perl script with unknown perl location

I'm developing a perl script which expected to be downloaded by Mac users with a very small knowledge of shell, linux etc, let's say office managers and accountants. After the downloading the script ...
1
vote
1answer
52 views

Shell script to list locked packages in FreeBSD

I'm trying to make a oneliner to be able to list all locked (forbidden to upgrade) packages in FreeBSD. Normally, you issue this command: pkg info -ak It outputs list of all packages in system ...
1
vote
3answers
99 views

How to count specific strings in file?

Using hash table to count specific strings, and out put a result with time it repeat. File A AAA BBB CCC DDD BBB DDD AAA CCC BBB AAA BBB CCC BBB Result AAA 3 BBB 5 CCC 3 DDD 2
1
vote
1answer
144 views

Basename gives extra operand error

I 'm using the following script to merge few pcap files into one using mergecap command. But when I run it it gives me a 'basename: extra operand /mnt/md0/capture/DCN/dcn_2014_02_04_00_11_47_598.pcap' ...
-3
votes
1answer
33 views

why does the dollar sign cause this command to be executed?

test_script.sh: #!/bin/sh D1="$(dirname $0)" echo $D1 D0="(dirname $0)" echo $D0 What I type on the command line: $ ./test_script.sh Output: . (dirname ./test_script.sh) What significance ...
0
votes
1answer
65 views

Can I use an if statement to detect if bash and dash are being run interactively? [duplicate]

After looking around for a while I've found several good pages describing how to check and see if a bash script is running interactively and there seem to be several methods, but one of them that I ...
2
votes
1answer
120 views

BASH : Array as String Buffer

Instead of displaying (or writing) every result once generated, i designed an Array based Buffer to store data and write it whenever the line counter reaches a MAX value. Here is the script : ...
3
votes
2answers
99 views

“history” stops working when run inside bash script

I am writing a simple script to grep my bash history to find a particular string. On the command line, I can do the following, which works fine: history | grep git However, when I create a bash ...
1
vote
1answer
85 views

Is there a graphical shell or scripting environment for Linux?

I would like to draw my scripts and connect commands like blocks of functions (something similar to Yahoo Pipes). Does such an environment exist or do I have to develop it myself?
0
votes
2answers
80 views

How do I edit /etc/rc.local? [closed]

Im using Raspbian and trying to edit /etc/rc.local. When I run sudo nano etc/rc.local or just sudo nano rc.local it creates a new file. And anything I try to edit in leafpad won't save.
0
votes
1answer
82 views

Calling an email script from another script using ssmtp on ubuntu

I have an issue with a script, which works fine except that it only sends email when I run it directly from the shell but when called during crontab it doesn't send the emails. There are 2 scripts ...
1
vote
5answers
120 views

Is there a way to make a Bash script enter a certain keystroke?

Is there any way to make a bash script enter a certain keystroke? What I'm trying to accomplish here is a script that will run Ctrl+B to exit tmux. EDIT: I see that several people are saying that ...
2
votes
1answer
154 views

How to strip color codes out of stdout and pipe to file and stdout

I have a program that uses printf with some tput mixed in it and I'd like to pipe the output to stdout as well as a file. I'd prefer to use sed since I don't want any unnecessary dependencies on my ...
4
votes
4answers
146 views

Keeping the number of files in the folder constant by deleting old files

I'm trying to create a script and run it in crontab every 5 min, so that the number of files in a folder always remain 50000. If there are more, I want the script to delete the old files. ...
1
vote
4answers
74 views

How to get started with bash? [closed]

I need a way to be able to run a script that will automate terminal commands, one after another. As I understand it, this is exactly what bash does. (Am I right, even on this count?) Where can I ...
0
votes
1answer
39 views

How I append the data of Multiple files into one file?

I want to append data of approx 500 files into one file and each of these files are located in their respective dirs. Also How i can verify the contents of merged file e.g How i verify that data ...
0
votes
2answers
24 views

How do I create a folder with a username and date as the folder name?

I need to write a backup script. I need to be able to run the script from any computer and have it pull the username and date as the directory name. Each computer has an admin account and a user ...
0
votes
1answer
35 views

How to measure rlogin time?

I need to monitor the time it takes to rlogin from one HP-UX machine to another. So I wrote this: #!/bin/sh result=`rlogin 10.10.10.1 << EOF exit EOF` result2=`{ time $result >/dev/null; } ...
2
votes
1answer
57 views

indirect variable expansion in POSIX as done in bash? [closed]

Is it possible, or is there some elegant hack to do indirect variable expansion in POSIX as can be done in Bash? For context, I'm trying to do the following: for key in ${!map_*} do # do ...
8
votes
7answers
732 views

bash: test if $WORD is in set

I am looking for a construct in bash, to decide if a variable $WORD is one of defined words. I need something like this: if "$WORD" in dog cat horse ; then echo yes else echo no fi does ...
2
votes
1answer
30 views

Count and merge consecutive patterns

I'm searching for a short snippet to find, count and merge consecutive duplicates using standard tools or a common scripting language. Say our input is: 1 2 2 2 7 22 a b b c c c c c d dd 2 2 c c ...
3
votes
2answers
227 views

Associative Arrays in Shell Scripts

I saw a trick for implementing associative arrays in a shell script. For example print array["apples"] could be scripted as echo \$array$key where key=apples. However, there was no mention of how to ...
2
votes
2answers
102 views

How do I check that a filename conforms to a pattern?

I'm tasked with writing a shell script which checks that a filename conforms to a specific pattern and I'm not sure how to go about it. The filename should follow a pattern which looks like: ...
5
votes
2answers
149 views

Local variables in zsh: what is the equivalent of bash's “export -n” in zsh

I'm trying to contain the scope of a variable to a shell, and not have children see it, in zsh. For example, I type this in .zshrc: GREP_OPTIONS=--color=always But if I run a shell script with the ...
0
votes
2answers
95 views

bc removes decimal point

This is related to Shell script too slow for output to Conky This code is nearly perfect: stdbuf -oL jack_cpu_load \ | grep --line-buffered "jack DSP load" \ | stdbuf -oL cut -d' ' -f4 \ ...
0
votes
2answers
60 views

Using AWK to delete line and output result

I have a text file and manage to find the line through output comparison. With the book title and author name. awk -F ':' '/KungFu Feet|Chuck Norris/' test.txt Kungfu Feet:Chuck Norris:12:1:1 Is ...
1
vote
3answers
169 views

Backup files with tar command and progress bar? [duplicate]

Can I see a progress bar or something not only ust the terminal screen output while backing up? Here is my shell script that I used backup with tar command: # !/bin/bash DATEJOUR=$(date ...
3
votes
3answers
98 views

Shell script too slow for output to Conky

I want the output of stdbuf -i0 -o0 -e0 jack_cpu_load | sed -n 's/[A-Za-z]*//g;s/ //g;s/.\{4\}$//;9,$p' to be displayed in Conky but, I suspect, Conky is starting the script with every refresh and ...
1
vote
1answer
104 views

how to send keyboard signal using a shell script

I have an application in graphical interface that when I run it, it's not opened in full screen mode, but when I use the keyboard shortcut Alt+Ctrl+M , it becomes fullscreen, I want to change the ...
2
votes
1answer
41 views

Pipe output of jack_cpu_load through sed

In the shell, when I pipe jack_cpu_load through sed, or cut, no matter what options I use it stops printing just before the lines I want to see. jack_cpu_load | sed -n 8p will print: Jack: ...
0
votes
1answer
59 views

Unknown syntax in /etc/rc.d/init.d/functions

Looking at the file /etc/rc.d/init.d/functions, I can see the following is declaring a number of variables as local variables. However, why are the variables killlevel and pid_file have an equal sign ...
4
votes
2answers
58 views

Find files newer than another file within each subdirectory

I have a folder structure like this /Class/Student/Unit/files Each Unit folder contains a file MarkSheet* that I update when I mark a students work. I need a script that tests if the student has ...
3
votes
5answers
88 views

Join two files, matching on a column, with repetitions

How can I get two files A and B, and out put a result like this: File A: 001 Apple, CA 020 Banana, CN 023 Apple, LA 045 Orange, TT 101 Orange, OS 200 Kiwi, AA File B: 01-Dec-2013 01.664 001 ...
-2
votes
1answer
39 views

automatic capturing top output by cronjob CENTOS 6.5 x86_64

I have this command: top -n 14400 -a -b -d 1 > /toplogfile.txt I want to make a script which is run by cron every day to capture top output, and if it is possible gzip the output file after the ...
1
vote
1answer
69 views

How would I detect a non-login shell? (In Zsh)

I want to create a script that runs when a Zsh instance starts, but only if the instance is: Non-login. Interactive I think I'm right to say .zshrc runs for all interactive shell instances, ...
1
vote
3answers
75 views

How to get numbers by using regular expression, but only last one

In this example I can get 00. expr match "00 foo 99.jpg" '[^0-9]*\([0-9]\+\).*$' I want to know how to get last number from string, in this case 99 by using regular expression. The string may ...
1
vote
1answer
77 views

Changing text color in c-shell

I can change the text color in the terminal permanently by adding this: export PS1="\e[0;31m[\u@\h \W]\$ \e[m" to the .bashrc file. Now I have to go into cshell, what is the corresponding way?
0
votes
0answers
31 views

Is there a difference between `command rspec` and `rspec`?

I want to call bundle exec rspec if Gemfile exists in current directory, and if it doesn't exists, call rspec itself. So I wrote like this. function rspec() { if [ -e 'Gemfile' ]; then echo ...
5
votes
5answers
109 views

A shell script to write selected fields to a single line

I have a log file trace.log which prints the time stamp, thread name and Transaction method and transaction ID as below. 2014-01-23 15:50:41,724 [catalina-exec-35] INFO TRANSACTION getConnection ...
0
votes
3answers
52 views

How can I add a script to embedded Linux

I have a script (let's say Hello World), that I want to include to my embedded Linux. I'm using Buildroot and want to start the script in Busybox. But because I'm cross-compiling for the target I'm ...
1
vote
1answer
23 views

Where can I find documentation on shell script syntax for using a regex within a variable construct?

I'm debugging a shell script (which I didn't write) that contains this loop: read line < "$pid_file" for p in $line ; do [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p" done ...
0
votes
1answer
97 views

shell script - echo command not printing in proper sequence

I have the following testfile.txt: string1 1 string2 2 string3 3 string1 2 string2 4 string3 6 string1 3 string2 6 string3 9 I have the following script: #!bin/sh ...
0
votes
0answers
34 views

Bash script to identify which init system the system currently using [duplicate]

I have to create a script that will mount my /usr folder as aufs. I compressed it using squashfs. I've managed to install a working systemd init in ubuntu which I am currently using. Because the ...
0
votes
1answer
66 views

shell script - reading from standard input versus a file

I have the following input file in.txt: a b c a b c I have the following script test.sh: # display unique rows while read line do echo $line done < $(cat "$@" | sort | uniq) # display all ...
2
votes
0answers
79 views

Number comparisons in BusyBox ash

I have the following script that extracts data from the EXIF command on my BusyBox ash-based system. I parse the date tag from the end of the file and use case as a final check to ensure the format ...