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

2
votes
1answer
23 views

When does one need to export a variable?

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 ...
1
vote
4answers
61 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 ...
-3
votes
2answers
22 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
2
votes
1answer
136 views

Programmatically get CPUs 'detailed' usage, like top/htop

htop has a great way to show CPU usage. It shows the activity (usage in %) of each cores, and each core gauge is divided into three parts : blue: low priority processes green: normal processes red: ...
2
votes
1answer
50 views

Capturing data from a Fluke 1620a via Bash /dev/tcp file descriptor

I am currently trying to develop a script that will connect to a Fluke DewK 1620a Themo-Hygrometer and pull the current temperature and humidity readings from the device. While these devices have a ...
37
votes
4answers
1k views

What exactly is an environment variable?

I know that VARIABLE=value creates an environment variable, and export VARIABLE=value makes it available to processes created by the current shell. env shows the current environment variables, but ...
2
votes
2answers
37 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: ...
2
votes
1answer
17 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 ...
2
votes
1answer
135 views

How to display a BASH X terminal and graphics in split view window?

I created a simple education tool using BASH script which runs in an X terminal. It displays a prompt, at which users can enter choices, as described in the Bash Guide for Beginners' Catching user ...
7
votes
2answers
2k views

Use the command bar in bash without I/O?

I really like the look of the output of bar But that script is only used for Input/Output operations. How can I use it as a replacement for sleep but with visual feedback? sleep 10
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

Is there a nice way to set directory/project local environment variables?

I have been working on several projects and they require different environment variables (e.g., PATH for different versions of clang executables, PYTHONPATH for several external modules). Whenever I ...
2
votes
1answer
45 views

Avoid that Ctrl-C disables input printing

On one of our servers, whenever I kill a process with Ctrl-C (e.g. to terminate a tail -f process), my input to bash is not printed anymore. I can blindly type reset, which solved the situation, but ...
2
votes
5answers
2k views

How do I pass a variable from my local server to a remote server?

I am trying to pass a variable from my local server (location1) to a remote server (location2). The purpose of the code is to copy a file from the remote server from a predefined location. In simpler ...
3
votes
1answer
47 views

Is it possible to show the current history line number when performing reverse search in bash?

Pressing Ctrl+R and typing py results in: (reverse-i-search) `py´: python I would like it to be this way: (reverse-i-search) `py´: n python where n is the history line number. I did not find an ...
4
votes
4answers
5k views

Progressbar in bash to visualize the time to wait

In a bash script sometimes you need the user to wait some seconds for a background process to finish. I usually use for example: sleep 10 How can I add a kind of progressbar to the script, so the ...
3
votes
1answer
31 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 ...
1
vote
2answers
72 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
19 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] ...
4
votes
1answer
217 views

Write the same file multiple times to one file using dd

I am trying to create large dummy files on a drive using dd. I am currently doing this: #!/bin/bash writeFile(){ #$1 - destination directory/filename, $2 - source filepath $3 - blocksize, $4 - ...
0
votes
1answer
8 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 ...
2
votes
2answers
37 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 ...
42
votes
4answers
4k views

What features are in zsh and missing from bash, or vice versa?

As a Linux user, I've always just used bash because it was the default on every distro I used. People using other Unix systems such as BSD seem to use other shells far more frequently. In the ...
0
votes
0answers
18 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
43 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
40 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 ...
1
vote
1answer
123 views

LFTP mirror includes - including other directories other than what I've included

My question: How can I make sure LFTP only includes files AND directories using --include or --include-glob, and not download a bunch of extra directories from the root of the remote that aren't in ...
0
votes
1answer
22 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 ...
3
votes
1answer
3k views

Why does the filename contain question marks when I run a script on my remote machine?

I have a tiny script that simply fetches the current date, runs a PHP script and redirect the output (and errors) to a filename containing the current date. DATE=$(date +"%Y%m%d") ...
2
votes
2answers
51 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: ...
4
votes
2answers
185 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 ...
1
vote
2answers
48 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 ...
0
votes
1answer
24 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' | ...
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
27 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
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
67 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 ...
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 ...
2
votes
5answers
6k views

Removing a directory from PATH

I'm trying to compile wxWidgets using MingW, and I have cygwin in my path, which seems to conflict. So I would like to remove /d/Programme/cygwin/bin from the PATH variable and I wonder if there is ...
4
votes
4answers
285 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 ...
3
votes
1answer
38 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 ...
2
votes
2answers
40 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
159 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 ...
11
votes
5answers
2k views

Using text from previous commands' output

EDIT April, 2015: If you have this same question I recommend also checking http://xiki.org/ I know this is not how terminals work, but I find myself often wishing there was an easy way of using ...
-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. ...
8
votes
4answers
255 views

How do you check if a file exists within awk? [-d 'filename'] failing

I'm trying to generate a list of users who have a home directory set which does not exist. It seems I should be able to do this with awk, but something is wrong with my syntax. It keeps telling me ...
1
vote
1answer
54 views

Bash script to get the result from rsync transfer and zip it as a directory in the original directory

OK, I guess this is weird. I have a small stage.sh script very simply has a bunch of commands: if [ "$(whoami)" == 'David' ]; then rsync -a --delete-excluded --exclude-from=.rsyncrc $(pwd) ...
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>)) ...
0
votes
1answer
46 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, ...