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

0
votes
1answer
15 views

bash cannot find mvn command after install

I tried to install Maven on CentOS 7, but afterwards typing mvn -version in the terminal results in bash: mvn: command not found.... How can I fix this so that I can call maven from the CentOS 7 ...
0
votes
2answers
31 views

How to tell the sizes of files and folders, sorted, and in MB, GB, instead of a long integer?

On a Mac, using Bash, I tend to do du -sh * to tell the sizes of files and folders in the current directory, in MB and GB. But if I want to sort them by the sizes, I might do du -sh * | sort -g ...
0
votes
0answers
7 views

RHEL Bash Script for Oracle WebLogic - Run command as another user; No such file or directory

I'm trying to run a test script which switches to a WebLogic 10.3.6 user and checks the status of the admin server. The script works fine when the variables are replaced with absolute paths, but this ...
1
vote
0answers
25 views

How to execute bash commands from C? [migrated]

Is there a way to run command line utilities, e.g. gzip, into a C app?
2
votes
1answer
29 views

Prevent glob expansion in foo=“*”; echo $foo [duplicate]

In Bash, when I do: foo="*" echo $foo It expands * to the contents of the current folder. How do I make sure it just prints a literal *? The same, by the way, happens with a regular echo "$foo", ...
2
votes
2answers
39 views

How to I prevent exec from keeping the script running?

I'm using exec like this: #!/bin/bash exec > >(tee /tmp/mylog.log) 2>&1 bash -c 'sleep 12312' & I want the output of the commands to be in a log file, and then I want to start a ...
0
votes
0answers
24 views

Command to see my current ip if proxy is applied only for a certain website

It might not be a relevent question here on so, but I tried on http://networkengineering.stackexchange.com and there are less users. So, I am not a networking guy and I have the next situation: I ...
1
vote
1answer
91 views

Listing functions defined in a “sourced” script?

I have a very simple bash script build.sh which defines - but doesn't invoke - a collection of functions, e.g. #! /bin/bash create_iptables_log() { # do stuff } apply_iptables_rules() { # ...
1
vote
0answers
35 views

changeshell -chsh (to zshell) asks for password often [on hold]

I use ubuntu 14.04 in my Desktop. I switch to zsh using the command chsh -s /bin/zsh from .bashrc. And when i open a new shell prompt, it always asks for a password. When i do source .zshrc, it ...
1
vote
1answer
35 views

Combine 2 prompts into one, showing error condition in red/orange

Not a very interesting question, but the answer could be beneficial to a lot of users. ;-) As everyone, I have a customized prompt. Mine turns red for root and is green for a normal user and a few ...
0
votes
3answers
39 views

Bash: Access parameter passed to last command [duplicate]

This is a situation I often find myself in: mkdir /Some/really/long/path/to/a/directory/ cd /Some/really/long/path/to/a/directory/ I know that ideally you would cd /Some/...etc.../a/ and then mkdir ...
4
votes
2answers
205 views

How to tell whether a duration is over one hour across multiple shell scripts?

I am trying to check running time and if it is more than an hour return an error, but the code returns false positives intermittently. In firstRun.sh, I read time as: export START_H=`date +%H` export ...
-3
votes
2answers
27 views

What is the exact difference between “/” and “%” in the expr command?

I want to know the difference between "/" and "%"! When I type and run the following command I get 0: expr 4 % 4 But when I run same command and replace "%" with "/" I get 1 expr 4 / 4 Thanks
4
votes
4answers
180 views

Split single string into character array using ONLY bash

I want to split 'hello' into h e l l o in an array using only bash, I could do it in sed with sed 's/./& /g' but I want to know how to split a string into an array in Bash when I do not know what ...
0
votes
0answers
9 views

Recursively replace a specific occurrence of a string in some files [duplicate]

Inside a folder, there are in certain files, a specific URL string (that is equal in all of them), that I need to replace with another URL string. What can I do?
2
votes
1answer
35 views

When does one need to export a variable? [duplicate]

Eons ago, when I first started assigning variables in bash, it was something along the lines of: export EDITOR=nano export PS1=something ...and the likes. And the habit of exporting has kinda stuck ...
3
votes
1answer
35 views

Run a command in background that sets env var or define function

> export foo=1 & [1] 9016 [1] + done export foo=1 > echo $foo > I know when running a command with & you spawn a new process and the export foo=1 is not setting env vars in ...
2
votes
2answers
47 views

Create variables and assign values via loop (bash)

Is there a way to create bash variables and assign them values via a loop? Something along the lines of: #!/bin/bash c=0 for file in $( ls ); do var"$c"="$file"; let c=$c+1; done EDIT: ...
1
vote
2answers
76 views

How can I select 3 character files in Bash?

I know that a question mark is considered a special character and it has special meaning. Question mark represents a single character that can be any type. In my practice lesson we have an example : ...
1
vote
1answer
22 views

custom nemo actions / bash script

i am trying to add a custom action to the nemo file manager. The purpose of the action is just to replace all whitespace in the filename by "_". My action file looks like this: [Nemo Action] ...
0
votes
0answers
20 views

Sqlplus environnement error

I have two virtual machines ubuntu, one is a server when I installed oracle 11g express, and the other is a simple client. My goal is to run an sql query remotely from the client machine. So I ...
1
vote
1answer
44 views

Why doesn't /bin/login appear in ps output when someone is logging in

I wanted to monitor what happens when a test user logs in to my CentOS 6.4 system, so I tried this to poll ps for /bin/login and strace the pid when it appears: until [[ $(ps -ef|grep -q [l]ogin)$? ...
1
vote
1answer
43 views

bash: -eq vs. == and `bc` output type

This snippet of code has been taken from a larger script, (humbly) simulating the non-existing abs() function: [[ $(echo "$val < 0" | bc) -eq 1 ]] && val=$(echo "$val * -1" | bc) So we ...
2
votes
2answers
42 views

Local variable as a part of global one

I have a question about something similar to this question, but I need to call global variable depending on local one. Say I want to pass either test, staging, or production as a variable to a ...
0
votes
1answer
25 views

sqldeveloper can't start

When starting sqldeveloper it crashes without any warning. It just shows a window for a fraction of second. By debuging : $ bash -vx /opt/sqldeveloper/sqldeveloper/bin/sqldeveloper it gives this ...
2
votes
1answer
19 views

Recover last argument of the last command in bash' vi mode

When using bash's vi mode (set -o vi), is it possible to recover the last argument of the last executed command? This is done in emacs mode with ESC+., and I would like to do it in vi mode as well. I ...
0
votes
1answer
11 views

Remap cursor keys in bash vi mode to <nop> (disable cursors)

When using vi mode (set -o vi) with Bash, is it possible to remap the cursor keys to so that they don't work (and be forced to use h, j, k and l movement keys)? Under vim (the editor), I can do it ...
1
vote
2answers
49 views

Log both stdin and stdout of program

What I want though is to run a program and log both the stdin and stdout, but I want the stdin to be supplied from a file. I thought script log.txt < input.txt would work, but it does not, because ...
2
votes
2answers
54 views

list all c files in sub directories and their parent directory

Assume I have a directory tree as follow: /home/xen/p.c /home/dan/t.c /home/jhon/l.c ... etc (many more users) I need to get comma separated (username,full path to c file) list as follow: ...
1
vote
1answer
22 views

Setting environment vars containing space with env

I'm trying to use env to set environment variables (read from another source, say for example a file) for a subprocess. Essentially, I am attempting the following: env VALUE=thisisatest ...
3
votes
1answer
31 views

Why does my application die without nohup?

I have a simple system (running on Debian) that works by invoking a script from /etc/init.d/rc.local At the bottom of rc.local I call myScript.sh who sets up some things, and then starts a binary ...
0
votes
1answer
27 views

How to echo tac'ed file into a new file [on hold]

I've got a blonde moment. How can I print this into a file: tac /driectory/somedirectory/myinputfile.csv | grep StackExchange | grep ',scan' | grep -v 'HDCU.*HDCU' | grep -v 'Sensor,Module' | ...
2
votes
0answers
41 views

Fixing my PATH variable

I am perplexed by the following problem and hoping someone can help me fix it: when I type echo $PATH, I get the output: /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games However, I ...
4
votes
2answers
189 views

Best and short way to run a program if another is not installed

I have this code: #!/bin/bash num=${1:-undefined} cmd=$(which {banner,echo} | head -n1) until [[ "$num" =~ ^[0-9]+$ ]]; do read -p "Type a number: " num done for ((num;num>=0;num--)); do ...
2
votes
2answers
41 views

cp won't work on current bash script's directory

I'm trying to copy some files from current directory in a bash script but the problem is that the cp command doesn't work with the current directory. I can use the following command without any ...
3
votes
3answers
160 views

Environment variables. Where are they saved in? [duplicate]

If I do not edit the .bashrc or other config files, the environment variables that I've setted are gone when I logout, or turn off the terminal. What I'm curious is, where are those 'temporary' env ...
0
votes
1answer
33 views

Color diff output

I am new to unix I wanted to format the unix files conditionally , I am currently working on diff command and wanted to know if it is possible to format the text of the diff command output. Example: ...
0
votes
1answer
47 views

How can I get a shell script to change directory for me? [duplicate]

here is a small test I ran, to try and move me back to root: #!/bin/bash pwd cd / pwd It returns the current working directory, and then the correct new one, but when the script finished executing, ...
0
votes
1answer
23 views

Hide curl output [duplicate]

I'm making a curl request where it displays an html output in the console like this <b>Warning</b>: Cannot modify header information - headers already sent by (output started at ...
-1
votes
0answers
36 views

Bash read user input and then call for a curl [duplicate]

I'm trying to execute a bash script that accepts user input and then according to that user input executes a curl request, the user input includes the query string that should be called using curl. ...
-2
votes
0answers
29 views

Unix KSH/Bash : Diff files for selected fields/columnwise only {GNU Bash 4.2 Environment}

I have two files: F1: abc|abc|abc|abc|abc| abc|abc|abc|abc|abc| abc|abc|abc|abc|abc| F2 abc|abc|abc|abc|abc| bcd|bcd|bcd|bcd|bcd| My questions are as follows: Suppose both files will have same ...
4
votes
4answers
286 views

How do I extract parts of a string to variables?

I have a line from some file like this: attempting to create a 512^3 level (with Dirichlet BC) using a 16^3 grid of 32^3 boxes and 800 tasks... I want to extract the 512^3, 16^3, 32^3 and 800 four ...
0
votes
1answer
24 views

Sanitise bash arguments

I have a script which takes user input and does a lot of things. One thing which I am worried about is it takes a file name and removes that file. e.g. rm -rf $arg1. A user could technically input / ...
1
vote
4answers
35 views

Anyway to pass a variable to bc, having a command to be executed?

I need to pass certain variable to bc to get the output in floating point, var1=$((<some operation>)) var2=$((<some operation>)) #Needs var1 var3=$((<some operation>)) ...
-3
votes
0answers
24 views

Write a script that will send the following information to the [closed]

Write a script that will send the following information to the screen, in the following format: Month Sales ===== ==== January 200 February 300 March 200 April 200 May ...
-5
votes
2answers
57 views

How to average a column in a text file without using ' character? [closed]

I need to do it without using the ' character. I could do it like this: awk '{sum+=$5} END { print "Average = ",sum/NR}' except this contains a '.
3
votes
1answer
39 views

Is it good practice to make an init script's lockfile immutable?

I recently created an init script, and decided to set lockfile to immutable to prevent external interference. The only downside I can think of is that if someone wanted to recursively delete ...
1
vote
2answers
73 views

One-Liner needed: Stop httpd if running already & Start httpd if not running

As part of a provisioning script for CentOS 7 I am in need to have a one-liner that performs the following. Unfortunately, I have no clue how to achieve that. If httpd is running then stop it If ...
0
votes
1answer
69 views

How to get rid of “\r” a the end of the line comming from pipeline in bash

#!/bin/bash sourcenode=$1 destnode=$2 path1=/root/test ssh root@"${sourcenode}" -t "echo "${path1}" | xargs -IDIR find DIR " | while read line do ssh root@"${sourcenode}" -t "stat -c "%a" ...
3
votes
2answers
27 views

locally created alias not being used if called using backticks (`)

I have come across this issue while trying to build up a script to do grep on multiple files for 10 different word. The script I created, is (minified) #!bin/bash alias grep='grep -n' out=`grep word ...