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

learn more… | top users | synonyms (2)

1
vote
1answer
25 views

What does /lib/lsb/init-functions do?

Can anyone help me in understanding the meaning of the following code from /lib/lsb/init-functions: base=${1##*/} Also it would be helpful if it was possible to explain how pidofproc function ...
2
votes
3answers
35 views

Is there some built-in (bash/gentoo) function to provide well-readable output to the user?

I am using the following simple function to provide some well readable output to the user. Now I am wondering if there is some kind of (gentoo-/bash-) built-in function to accomplish this task, as ...
3
votes
3answers
51 views

Redirecting stdout to terminal and file without using a pipe?

I have code, that goes something like this: #!/bin/bash VAR=0 func() { VAR=$((VAR+1)) echo 'Logging information.' } func 2>&1 | tee 'log.txt' echo "Should be 1: ${VAR}" When ...
11
votes
3answers
298 views

Finding the correct tmp dir on multiple platforms

I have a script that needs to create temporary files for its work, and clean up after itself. My question is about finding the right base directory for the temporary files. The script needs to work ...
0
votes
1answer
33 views

Debugging with shell programming and cpp files?

I am having trouble understanding how my code is working. I am new to this project and never learned unix before. My coworker quickly showed me how to run the program but didn't explain how it worked ...
1
vote
0answers
15 views

Take the unknown contents of variable as literal in sed [duplicate]

I have two files: a.patterns contains patterns in a one per line way "`" "^" "<" "<(" "<)" "<[" "=" ">" "_;|^+*+?@" and b.data contains comma separated values. 1,1,0,"*",1 ...
1
vote
2answers
60 views

How do I expect 'echo -e “? \c”'?

I'm an absolute newbie to the UNIX world and have been asked to write a script that interacts with another one - but I'm stuck. The script that I interact with echos the following and I need to send a ...
-2
votes
4answers
41 views

How to ignore the lines starts with # using grep / awk

cat /etc/oratab #test1:/opt/oracle/app/oracle/product/11.2.0.4:N +ASM2:/grid/oracle/app/oracle/product/11.2.0.4:N # line added by Agent test2:/opt/oracle/app/oracle/product/11.2.0.4:N ...
1
vote
1answer
57 views

How to run “&” operation sequentially

From my script I am running following commands: SCRIPT_1="ksh -x script1.sh & ksh -x script2.sh"; SCRIPT_2="ksh -x script3.sh & ksh -x script4.sh"; eval $SCRIPT_1; sleep 20s; eval ...
1
vote
1answer
27 views

using bash script to sort text in a file

I would like to sort the output of multipath -ll into a csv type of file using bash script. For example # multipath -ll would give the following output 360060e80056fc30000006fc30000513c dm-41 ...
2
votes
0answers
20 views

“login -qf” as root results in “Login incorrect” error

I'm trying to install pow on an OS X machine.* Some of pow's components have to run as root, so part of the setup process involves running an installation script with sudo. The problem is, this setup ...
3
votes
1answer
32 views

Problem with passing parameters containing spaces and wild card characters

I have a problem passing parameters if the parameters may contain wildcards and/or spaces, if those parameters are optional. Since this sounds pretty abstract, let's have a small example: The ...
-1
votes
1answer
35 views

How to name a directory by combining two variables?

I want to name a directory by combining the the values of two variables. eg: dirname="$var1" '.' "$var2".
6
votes
3answers
170 views

sed with multiple expression for in-place arguement

I am trying to replace multiple words in file by using sed -i #expression1 #expression2 file Something 123 item1 Something 456 item2 Something 768 item3 Something 353 item4 Output (Desired) ...
2
votes
2answers
48 views

Using Diff on a specific column in a file

Will it be possible to use diff on a specific columns in a file? file1 Something 123 item1 Something 456 item2 Something 768 item3 Something 353 item4 file2 Another 123 stuff1 Another 193 ...
3
votes
4answers
62 views

Inner loop conditions shall depend on outer loop run

How can I build an inner loop such that the loop condition depends on the outer loop run? My very situation does probably not matter for the code I am looking for, but here it is: I have a crawler ...
2
votes
2answers
65 views

What is the purpose of using shift in bash scripts?

I have came across this script: #! /bin/bash ...
3
votes
1answer
59 views

sed repeating the last line in the stream

I have code in a script similar to this... smbconffile="/etc/samba/smb.conf" sed -i 's/.*[\[CMI\]]/\[CMI\$\]/' $smbconffile && echo "Success" || "Failed" sed -i 's/.*[\[LOCAL\]]/\[LOCAL\$\]/' ...
3
votes
3answers
56 views

source /dev/stdin doesn't work as expected

Let's start with simple tests that work for me to check that source /dev/stdin can be used at all. # echo -ne 'echo a\necho b\n' | source /dev/stdin a b Now I would like to source an actual ...
0
votes
1answer
84 views

Start script on boot up?

I want to run a script when the system starts. The script is: #!/bin/bash gnome-terminal --tab -t "MyPC" -e "sh -c 'nohup firefox & nohup gedit & bash'" --tab -t "MYPC2" -e "sh -c 'ls -al;ls; ...
-4
votes
0answers
23 views

I am getting some data using curl command into command line. I need to know how to search the data in command line in linux [on hold]

I am getting some data using curl command into command line. I need to know how to search the data in command line in Linux code curl -s -X POST -H "Content-Type: application/json" -T ...
1
vote
0answers
20 views

POSIX compliant shell script not portable because of the tools used inside [on hold]

I've written a script which runs in a strictly POSIX compliant shell without trouble on my machine but a buddy of mine couldn't execute it. It seems as if his machine has different versions of tools ...
1
vote
1answer
16 views

xmessage in a script freezes

I use the following script called from a udev rule in order to automate backup: #!/bin/bash export DISPLAY=:0 export XAUTHORITY=/home/gauthier/.Xauthority # ... other things like offering abort, ...
0
votes
0answers
10 views

I'm calling the Google Analytics Realtime API and getting back a JSON object. I need a script to determine if a value has changed [migrated]

I'm calling the Google Analytics API with an HTML page containing Javascript calls. It returns a JSON object like this: { "rows": [ [ "Submit", "6" ] ] } I'm currently ...
0
votes
1answer
59 views

bash: What is the difference between these two script variants?

(Note: Both of these examples may require GNU or BSD find and may not work as-is with the POSIX "edition" of find). Both of the scriptlets below must be understood as excerpts from way more complex ...
1
vote
0answers
18 views

run a certain file (e.g. a .py) when a certain image, .wav or excel file get opened [duplicate]

Recently, me and my friend have purchased a Palm Vein Scanner. the goal was using it in a mini-project as a new door lock system. we are connecting it to a Raspberry Pi to run the software on it. ...
1
vote
1answer
24 views

Shutter Script(s)

When i play some games with wine , i must not change the window , because of that , the game crash or that window are fill of black. im using xfce4 desktop , when i press "PrintScreen" key from ...
3
votes
3answers
418 views

Replace %20 with a space in filenames? [duplicate]

I have a list of files that are using %20 to indicate a space in their names. I'm currently trying to do the following to change them all from %20 to a space " ". for x in *.txt do mv $x $(echo $x ...
1
vote
1answer
35 views

Number of packets sent and received on an interface

I'm interested in creating a script which prints total number of received packets and sent packets on an interface. The output should be like: interface TX: number RX: number Can anyone help me ...
-1
votes
2answers
134 views

delete files having a certain pattern in their names

I want to delete all files that have two numbers and a dot in beginning of their names for example: 01. abc 02. xyz
-3
votes
1answer
31 views

Have a script (on server) download a file on your computer (local machine) [closed]

I am setting up a special kind of script for a project that I am working on. I'd like my script, when executed, to take a file that is on the server and put it on the computer. I have no idea how I ...
-3
votes
1answer
52 views

If statement to compare files

I need to make an if statement that: compares the files finds the differences between them gets a word count of both files pastes the information from one file to another But I do not know if I'm ...
0
votes
1answer
32 views

Bash Script Not changing Directory

I have a small script I am working on where I need to read in a few Strings: #!/bin/bash echo "Enter SUID: " read $uid echo "Enter Tag Number: " read $dicomTag dicomDump() { arg1=$1 ...
2
votes
3answers
127 views

Find files newer than a day and copy

I am working on a script that will copy ONLY files that have been created within the last day off to another folder. The issue I am having is the script I have copies all of the files in the source ...
6
votes
1answer
144 views

Is it better to use $(pwd) or $PWD?

I encountered BASEDIR=$(pwd) in a script. Are there any advantages or disadvantages over using BASEDIR="$PWD", other than maybe, that $PWD could be overwritten?
1
vote
3answers
52 views

Calculate and round numbers up in bash

I'm struggling with a slight variation on: How to calculate by taking first field and How to round floating point numbers in shell? I have a file that looks like (space between columns): 1533 ...
4
votes
1answer
99 views

cmd2 `cmd1` vs cmd1 | xargs cmd2

I'm trying to find a file with find and then pass the found path to sqlite3. I'm only dropped into the sqlite> prompt if my command is of the form: sqlite3 `find . -type f -iname "*.db" | head ...
3
votes
1answer
134 views

bash: non blocking read inside a loop

I have a following small bash script var=a while true : do echo $var sleep 0.5 read -n 1 -s var done It just prints the character entered by the user and waits for the next input. ...
1
vote
1answer
51 views

Is there a simple way to find out the last line executed in a bash script?

In answering this question please bear in mind that I am a beginner and a bit out of my depth. I'm running a bash script which contains a for loop which will run thousands of times. Somewhere in this ...
2
votes
2answers
95 views

How to retroactively make a script run as root?

I'm writing a shell script, that needs to be run with root privileges. I can check if a user has root privileges with sudo -nv || echo "no sudo", but that doesn't help me, if his credentials are ...
0
votes
2answers
52 views

Command to see if a word is in a list of files and output how many files it is in

There is a similar question to mine already but mine has a slight difference. I want to see how many files contain each word. When a file has a word then it increments the counter and then continues ...
0
votes
1answer
31 views

Syntax of process substitution

I am really having some trouble understanding pipeline substitution. I have a program that I run with the make command that writes to stdout. What I want to be able to do is parse through the output ...
4
votes
2answers
41 views

Is there a way to have a function in my bash script auto run on any command error?

I'm writing a shell script that needs to do a bunch of commands and every command depends on every previous command. If any command fails the entire script should fail and I call an exit function. I ...
1
vote
1answer
78 views

Storing longer text output in memory in shell variables vs Writing to disk

I have the below call to db2 command line tool inside a loop which runs 100k iterations. (the db2 output is 5 rows of 20 chars approx per each call, total of approx 100k calls. The input to SP is ...
23
votes
2answers
2k views

Why does ( echo “”; exit 1) not exit the script?

I have a script, that does not exit when I want it to. An example script with the same error is: #!/bin/bash function bla() { return 1 } bla || ( echo '1' ; exit 1 ) echo '2' I would assume ...
0
votes
2answers
42 views

Using variable with awk -v in a shell script

I am modifying/re-writing some of the scripts written by former employees of my company and in one of the shell scripts I found the following line. b=`benchmark=30;grep "Waiting for timer" wk.txt | ...
1
vote
1answer
35 views

How to continue a script after X has been closed?

I recently installed RetroPie on my Raspberry Pi and I'm trying to find a way to (once I'm in LXDE) run a shell script that kills X and then starts EmulationStation. I can kill X with pkill x but then ...
0
votes
2answers
30 views

output a variable value using echo command [duplicate]

I want to output number of lines in text file.So I am using echo command but I am getting filename along with number of lines when I run the following code: echo "$page" > t total="$(wc -l t)" ...
2
votes
2answers
57 views

Check files for conventions

I need a script that checks and lists all text files for project conventions. With conventions I mean for example: UTF-8 encoding No trailing white spaces Newline at the end of file No not-ascii ...
0
votes
1answer
23 views

Count number of times each line repeats itself, In case Insensitive manner

I have a file like a A b c I want to print number of times each line repeats it self in a case insensitive manner. I found below command to be useful: tr A-Z a-z | uniq -c | sed -e 's/^ *//' -e ...