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

learn more… | top users | synonyms (2)

3
votes
2answers
34 views

Append unix timestamp to files with space using a script

This script works fine for all files recursively as well but it does not name files that has space in between. For example it throws error for the files "this is a test.txt" or "test file.txt" Any ...
0
votes
1answer
12 views

how to export nam of logged in user correctly?

I have the following script here. #!/bin/bash #some initial variables DLURL=https://raw.github.com/horvan/drubuntu/master DIRURL=/opt/.drubuntu #Get files to run the installation wget -O ...
4
votes
5answers
143 views

What command(s) will feed a tab-delimited text file and cut each line to 80 characters?

I've got multiple-line text files of (sometimes) tab-delimited data. I'd like to output the file so I can glance over it - so I'd like to only see the first 80 characters of each line (I designed the ...
2
votes
2answers
44 views

Use config file for my shell script

I need to create a config file for my own script: here an example: script: #!/bin/bash source /home/myuser/test/config echo "Name=$nam" >&2 echo "Surname=$sur" >&2 Content of ...
1
vote
2answers
36 views

Creating a list of files, removing “duplicates” with different suffix

I have a problem that (I think) require a bit of script-magic - not sure what would be best though... I have one directory with lots pictures in different formats - jpg, gif, png, tiff and svg. Some ...
1
vote
3answers
42 views

cd works in shell but not in script [duplicate]

I frequently have to cd from $HOME to a particular long directory path. So I thought I'd put a cdscript in $HOME to make getting there a little quicker. cdscript: #!/bin/sh directory="/some/big/long ...
1
vote
0answers
11 views

Output Tmux Output to the Terminal

I'm using supervisor to monitor keep a process alive, but I do need to have contact with that process every now and then to provide user input. I would normally use tmux for this, but when I use ...
5
votes
4answers
315 views

Remove next-to-last extension in a file name

Suppose a folder with many files with bad extensions,for example Song1.avi.mp3 Song2.avi.mp3 Song32.web.mp3 Song23.mp4.mp3 Song2a.mp9.mp3 I want to remove only the second field (web, avi, mp4). I ...
-1
votes
2answers
18 views

How to compare strings in Bash script [on hold]

I have one strings like "9999991385" now I want to match first 4 digits from one file if it's match or not ??
10
votes
4answers
712 views

How do I run a command and get its exit code in fewer characters?

I used to write my scripts like this: some_command while [ $? -ne 0 ] ; do sleep 1 some_command done It always irked me that I have to write some_command twice. Can I put it inside the loop ...
0
votes
4answers
64 views

Time calculation [on hold]

I have a text file containing flight times, hours and minutes one per line: eg 8 minute(s), 28 second(s), 870 milliseconds 19 minute(s), 24 second(s), 398 milliseconds 18 second(s), 876 milliseconds ...
3
votes
1answer
111 views

bash permission denied but sh works

A little script of mine on a mounted windows partition refuses to be executed directly (shebang is #!/bin/bash), but interestingly calling it with bash/sh works. The script is simply a collection of ...
-5
votes
0answers
47 views

to easily delete and undelete files [closed]

Instead of immediately deleting a file, the del command will move the file to another location known as the trash can. The undel command will restore a file from the trash can, if possible. Safely ...
4
votes
1answer
72 views

Script for “battery level reminder”

I want to plug in the laptop battery charger when the battery level goes down to 40% and then plug it out when the battery charge level reaches 80%. And for that reason, I need a script that would ...
2
votes
1answer
39 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
38 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
54 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 ...
16
votes
3answers
405 views
+100

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
38 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
18 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
66 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
44 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
63 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
30 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
28 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
35 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
191 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
55 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
65 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
69 views

What is the purpose of using shift in bash scripts?

I have came across this script: #! /bin/bash ...
3
votes
1answer
62 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
64 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
89 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; ...
1
vote
0answers
22 views

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

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
18 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
60 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
26 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
430 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
36 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
138 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
54 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
33 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
174 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
53 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
135 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. ...