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

learn more… | top users | synonyms (2)

1
vote
1answer
46 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
35 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 ...
0
votes
1answer
45 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 ...
1
vote
0answers
14 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
27 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
32 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
149 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) ...
1
vote
2answers
45 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
58 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 ...
0
votes
1answer
47 views

What is the purpose of using shift in bash scripts?

I have came across this script: #! /bin/bash ...
3
votes
1answer
58 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
53 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
81 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
15 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
58 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
414 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
33 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 ...
0
votes
2answers
128 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) [on hold]

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
31 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
125 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
121 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
48 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
91 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
74 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
34 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
29 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
56 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 ...
2
votes
3answers
140 views

find, xargs and mv: renaming files with double-quotes, expansion and bash precedence issue

Ok, I'm simply trying to strip out double-quotes in my filenames. Here's the command I came up with (bash). $ find . -iname "*\"*" -print0 | xargs -0 -I {} mv {} {} | tr -d \" The problem is the ...
-2
votes
1answer
46 views

Sorting a file based on second column in a Tab Spaced file [closed]

This may be a duplicate, But I have a Tab separated file and I need to sort the file based on second column which are float values. sort -s -k2,2gr -t$'\t' The code states it is to sort based on ...
1
vote
3answers
41 views

Evaluation an expression and rounding up to three decimals

I have an expression "5+50*3/20 + (19*2)/7" I need to round it up to 3 decimal places. The answer to this is 17.92857142857143. When I use the script below it is giving me 17.928. The answer should be ...
1
vote
6answers
377 views

Print numbers from 1-50

x=1 while [ $x -le 50 ] do echo $x $x=(($x + 1)) done I have wrote the above code. What seems to be a easy task in many programming languages is giving this error for me. solution.sh: line ...
3
votes
2answers
42 views

Script to replace all symbolic links to a target to point to another target (in the same directory)

Given the following contrived example: $ mkdir -p a/b && touch a/b/original-target && touch a/b/new-target $ mkdir -p c1/c2 && cd c1/c2 && ln -s ...
2
votes
1answer
57 views

Bash variable ${0##*/}

I am trying to understand the variable ${0##*/} that I encountered in a bash script. I understand that $0 contains the name, or the path, of the script, then ## works as in ${parameter##pattern} ...