Questions about bash only, as opposed to other Bourne/POSIX shells. For all Bourne/POSIX-style shells, use the /shell tag instead.

learn more… | top users | synonyms

5
votes
6answers
489 views

How do I check if a variable exists in bash?

I need to check a variable's existence in an if statement. Something to the effect of: if [ -v $somevar ] then echo "Variable somevar exists!" else echo "Variable somevar does not exist!" ...
-1
votes
2answers
35 views

Enter a variable into a command in bash

My question should be simple for you guys. I am writing a simple script that runs a command but the file it would need is always different. Is there a way for it to ask: "Where is the file?" And ...
0
votes
2answers
34 views

Replace spaces by underscores in files: Error in my bash script

I don't understand the error in my bash script. #!/bin/bash newFile="" for file in * do newFile={$file/ /_} # so as to replace spaces with underscores mv {$file} {$newFile} done It ...
2
votes
2answers
64 views

Compare 2 Files if it falls between a range of numbers

I have 2 files, File 1: 4 7 2 File 2: 1 5 Alpha 6 10 Bravo 11 15 Charlie 16 21 Delta 22 30 Echo I want to compare every entry in file 1 if it lies between col 1 and col 2 of file 2 (should be ...
0
votes
2answers
57 views

How to execute multiple .command files simultaneously?

I have a folder of .command files (regular task) on Mac OS X , which i would like to execute simultaneously. At the moment, i have been iterating through each file in the directory one by one to ...
0
votes
4answers
32 views

Test if integer series is strictly increasing

I would like to test if a list of integer values (e.g stored in a file, one per line) is strictly increasing, using a bash script. Is there any simple/concise way to achieve that?
1
vote
0answers
20 views

GNOME 3.14+ launch new gnome-terminal and set title

To the disappointment of many, tab/window title can't be set anymore with --title I use bash. I have had a few aliases I have used to connect to remote servers with. alias c:prod='gnome-terminal ...
1
vote
3answers
196 views

Put big data of heterogenous byte offset into arrays by AWK

Assume the data consists of byte offset which is not fixed i.e. the distance of two subsequent file headers varies. The point of this thread is to go through each size of events separately in arrays. ...
4
votes
2answers
97 views

How to search for and replace text between two markers in bash script, with content from another file?

Say I had a block of text in the ~/.bashrc: #~/.bashrc # ...some commands... # aliases alias suicide='sudo rm -rf /' # end aliases # other commands I wish to replace that block of text with some ...
4
votes
1answer
32 views

Aliases fail to persist after sourcing script

Here is my script: echo "Defining aliases" echo $$ echo " s=screen v=vlock -a j=jobs " | sed '/^$/d' | while read alias do echo $$ alias "$alias" alias | wc -l done And here is its output: ...
0
votes
1answer
17 views

Comparing Oracle version in bash script

I'm trying to create a bash script to install an application that requires Oracle 11g client. How can I read in the version info within the bash script? sqlplus when run in Putty spits out the ...
0
votes
0answers
32 views

How to get the placeholder's value which is stored in a different file (same directory) [closed]

With the conditions: I cannot use any XML parser tool as I don't have permission , read only My xmllint version does not support xpath, and I cannot update it , read only I dont have xmlstarlet and ...
0
votes
2answers
68 views

PATH variable is not working [closed]

I'm trying to set up PATH like this: export AMBERHOME=/home/pablo/amber14 PATH=$AMBERHOME/bin:$PATH PATH=$PATH:/home/pablo/tinker/bin However the PATH variable seems not to work properly. I dont ...
4
votes
2answers
41 views

How can I disable bash traces?

For any command that I execute in the terminal a comment like + command appears. For example for ls it shows + ls --color=auto.
1
vote
1answer
25 views

Magic environment variables in gnome-terminal

I had installed a proxy software (cntlm) on my machine. It sets the environment variable http_proxy to 127.0.0.1:3128. Now I've uninstalled the program using apt-get remove cntlm. However I'm able ...
0
votes
1answer
50 views

Remove the exact same matching lines with sed

I have this bash script: sed -i -r '/deb http\:\/\/httpredir\.debian\.org\/debian jessie main/d' /etc/apt/sources.list sed -i -r '/deb http\:\/\/httpredir\.debian\.org\/debian jessie\-updates main/d' ...
0
votes
1answer
11 views

how to access through the matches in file-name completion?

In case of file-name completion, is there a way to access through the matches that get displayed after a double tab?
2
votes
2answers
161 views

Slash and backslash in sed [duplicate]

I want to use sed to change a slash into a backslash and a slash, i.e. / -> \/. But it does not work. Here a small example: #!/bin/bash TEST=/etc/hallo echo $TEST TEST=$(echo $TEST) echo $TEST ...
1
vote
2answers
39 views

How can I delete <93> <94> symbols in file? It is equivalent “ ”

I copied text from a PDF file in bash - vi and I get lines like this: echo <93>The Hypotenuse is $hypotenuse<94> I tried to change that in vi by: s/<93>/"/g But: E486: ...
4
votes
6answers
196 views

Loop in text files shell script

I have a list of files in one directory and a set of jpegs corresponding to each file in another directory. I need to loop over all files, and for each file name, determine the target directory. For ...
4
votes
2answers
48 views

date processes first parameter incorrectly if it is not 1

I am using date (GNU coreutils) 8.22 and having some trouble to calculate a date after a given one. Say I want to use 1st of February, for example: $ date -d'1 February' Sun Feb 1 00:00:00 CET 2015 ...
-3
votes
0answers
27 views

Add '/' at the end of line without directing to a file in unix / shell scripting [closed]

Is it possible to add '/' at the end of a line having the pattern SUCCESS? Without directing the output to text file. E.g. When I execute the script the output may have "SUCCESS" pattern. If then I ...
0
votes
0answers
20 views

how to hardsubbed avi files with Hnadbrake CLI bash script

is there a way to hardsubbed avi files with Handbrake CLI ? i use this bash script below to convert all avi files in a directory but have no idea how to make hardsubbed video with this bash script. ...
2
votes
2answers
29 views

How to run x instances of a script parallel?

I have script I'd always like to run 'x' instances parallel. The code looks a like that: for A in do for B in do (script1.sh $A $B;script2.sh $A $B) & done #B done #A The scripts ...
0
votes
3answers
99 views

Where is .bashrc file found in Linux?

I am not finding my .bash_login and .bash_profile root@linux:~# locate .bash* /etc/bash.bashrc /etc/skel/.bashrc /etc/skel/.bashrc.original /home/noroot/.bashrc /home/noroot/.bashrc.original ...
2
votes
4answers
120 views

How to see if there are any matching characters in a string?

I'm making a card hand generator, and I want it to note if a specific hand is generated, like a three of a kind or a full house. I was trying to figure out how to do it, and I thought of using grep on ...
0
votes
1answer
28 views

Clear terminal window before tail -f output

I have the following script running every 3 minutes with cron: #!/bin/bash cd ~/Documents/Fetch/ wget remotehost/data.txt --output-document=tmp cp tmp data.txt rm tmp To fetch a self-generated php ...
0
votes
3answers
32 views

Shell pattern matching and arithmetic operators (+ - * / %)

This looks so simple but it isn't: [[ "1234+5678" =~ [0-9]+(\s*(\-|\*)\s*[0-9]+)* ]] && echo $? returns a 0. However, it actually should not do that, as only minus (-) and multiplication (*) ...
-1
votes
1answer
86 views

mv command does not work in shell script [closed]

I want to rename a folder with a bash-script. I don't know why this command is not working in a shell script, but directly in the terminal is working without problems. ...some code... ...
8
votes
9answers
432 views

awk or sed to lowercase/uppercase only one character in string?

Is there a way how to uppercase/lowercase only one character in some string? Input Example: syslog_apr_24_30 syslog_mar_01_17 Desired output: syslog_Apr_24_30 syslog_Mar_01_17 Note please the ...
-4
votes
3answers
34 views

find and replace strings with another string command line

I have a Ad-blocking hosts file with 0.0.0.0 IPs pointing to URLs. How to replace 0.0.0.0 with 127.0.0.1 command line without any visual text editor ? Manually doing this with nano , vi etc. is ...
1
vote
3answers
71 views

How do I get the current line count from xargs?

I want to grab every 5 images in a directory and merge them together into a new file with a unique filename per 5 image group. find *.jpg | xargs -n 5 -i convert {} -append {#}.png This is really ...
0
votes
1answer
11 views

How do I change the keybindings for the dialog command

According to the documentation here: You can override or add to key bindings in dialog by adding to the configuration file. Dialog's bindkey command maps single keys to its internal coding. ...
2
votes
0answers
32 views

How prevent users from running commands via dot slash for a directory?

Does anyone know if it is possible to restrict execution of commands via dot slash notation for a directory? The environment is bash on Linux. For example, I have a directory /usr/local/app/bin. In ...
0
votes
1answer
26 views

Terminal doesn't calls 'then' a syntax error, command not found [closed]

I am a newbie for linux. I have centOS7. I am running a very simple script from BASH. I execute the chmod command and then run the script file from terminal, I get an error saying that if command not ...
0
votes
2answers
61 views

Bash script that detects if a file is the correct size

I'm trying to make this bash script dispatch and email when it detects that a certain type of file (files ending in ".gz"), which was last modified 24 hours ago, is below a certain size in a ...
-1
votes
1answer
39 views

inittab respawn and rc.local

At the moment I have a daemon starting at boot using rc.local by the following line. su -l user -c '/dir/daemon' but I would like to start this process as a service with respawn. I found out that ...
-2
votes
1answer
22 views

Get CIDR of my IP on the WAN

I have a script that updates some remote systems with my laptop's IP and CIDR on the WAN, how the Internet sees me, in other words. I use the following to get my IP on the WAN in bash: dig +short ...
0
votes
2answers
19 views

Asterisk behaviour in creating links

I am trying to create symbolic links for a set of files. Suppose I want to link all the files with the pdf extension from an origin_directory to my present directory. Up to now I have this command: ...
0
votes
0answers
19 views

Can rpm call an external script stored somewhere in the package during installation?

I have a package which is being retooled for in house purposes. Mostly making changes to the configuration files. The files need to be somewhat dynamic so changing the config files at source isn't ...
5
votes
2answers
73 views

In a loop over an array, add an element to the array

I have a problem with for loop in bash. For example: I have an array ("etc" "bin" "var"). And I iterate on this array. But in the loop I would like append some value to the array. E.g. array=("etc" ...
1
vote
2answers
22 views

How to switch to bash on DEVISH?

With the update from BasilOS Quad to Pentus, DEVISH became the primary shell(replacing bash)... I am completely unfamiliar with DEVISH, so I need to be able to switch back to bash... I tried chsh but ...
0
votes
2answers
43 views

Best way to iterate through the following awk command

I have the following awk statement awk '/^string$/{i=1;next} i && i++ <= 2' file This will search for string and then print 2 lines down. So as an example $ cat file string aaa bbb ccc ...
-3
votes
2answers
39 views

sed or awk to get a string

I have a shell script with string=<deploymentTargets xmi:type="appdeployment:ClusteredTarget" xmi:id="ClusteredTarget_143378365 7353" name="cluster1"/> I want the value between name=" and ...
1
vote
1answer
51 views

Bash script to edit text in csv-format

As part of an inventory bash script I am checking SFP modules and adding them to a .csv-file. The format currently looks like this, with varying lengths: RO01;1000BaseSX SFP;1000BaseSX SFP ...
0
votes
2answers
68 views

Using multiple awk commands within single line

Here is what am trying to do: My data is in sets of rows within same file (the variables vaa vbb are looping over it and am able to control it as required) What i need is to add an extra column before ...
0
votes
1answer
26 views

Understand the order of commands in bash when functions are involved

I have an example where I define a function named f which prints blah and then stores command itself and all its arguments into variable $@: # f () { echo blah; "$@"; } # df -h | f blah # df -h | f ...
1
vote
1answer
26 views

Unable to run the script in cron via manifest

I am trying to deploy a script to agents and run the script using cron every hour. When I am running puppet agent -t I am getting error: Error 400 on SERVER: Invalid parameter path on ...
0
votes
3answers
54 views

In bash, how to call a variable and wrap quotes around its value as part of a command without causing the variable name to become a string literal?

So I want to add 10 seconds to a time. The command to do that came from here. To illustrate: STARTIME="$(date +"%T")" ENDTIME="$STARTIME today + 10 seconds" CALL="$(echo date -d $ENDTIME ...
0
votes
1answer
13 views

Install script - sudo authorisation compatibility?

I am currently updating a few scripts, and am planning on releasing some useful ones so others can use them (so they need to work across a wide range of machines without crashing, and without breaking ...