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

3
votes
2answers
305 views

How does Bash get the output of an executed program?

When I execute a program in Bash, for example, [ls][2], it sends its output to standard output (fd &1). And the ouput of the executed program is displayed in the terminal. How does Bash/terminal ...
0
votes
0answers
12 views

Remote shell weird behaviour using arrow keys and editing commands

I am logged in remotely over a rather slow connection and the terminal is doing weird things when trying to edit commands. For example, I start with find . -type f | xargs grep "_RWSTD_STATIC_CAST" ...
0
votes
2answers
62 views

Check if a file is a text file in bash

I am trying to make a check to see if the file being attached to the email is a text file, and if it is not it returns an error. However during testing, I provide a valid text.txt and it returns the ...
0
votes
2answers
31 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)" ...
0
votes
1answer
25 views

Installing PHP on OS X. Syntax errors?

When installing OS X on Yosemite with curl -s http://php-osx.liip.ch/install.sh | bash -s 5.6, I get the following: **** [WARNING] Detected OS X Yosemite 10.10. As this is quite new, there may be ...
1
vote
4answers
89 views

Error setting variable to the length of an array in bash

I have the snippet below in a larger script to basically take my balances out of ledger into two arrays so I can print them the way I want to view them. #!/bin/bash assets=("assets:checking" ...
0
votes
1answer
43 views

Script thinks input is a command?

I'm just getting started on a script that does basic shell commands, but the second function, which is supposed to take a valid year and month and plug them into cal, is returning with this error: ...
0
votes
2answers
27 views

making my UID work the same on all servers

I have a user id on 5 servers same user name. for one of the servers I have modified my .bashrc and added a bunch of new features to customize how my UID command line, etc work. What is the best way ...
0
votes
1answer
37 views

Bash 4.3 yum repository for Amazon Linux

I'm trying to get bash 4.2 (or a more recent version) on Amazon Linux in ec2. The default repository only has Bash 4.1. I'm looking for a yum repository with a recent version. $ sudo yum install ...
2
votes
1answer
24 views

Show alias replacement text in .bash_history file

Given that I have the following alias in one of my bash initialization files (.bash_profile etc.): alias gs='git status' How can I get my .bash_history file to show the replacement text: 'git ...
2
votes
1answer
53 views

calling Bash Function from alias definition

I am using Xilinx ISE, a program that requires to source a vendor script to setup the path for all its tools. Since this script breaks some functionalities of my shell I do not want to source it on ...
1
vote
1answer
20 views

vim :grep using the bash 'globstar' option

I am (slowly) switching to Vim for everyday Ruby on Rails coding (Linux Cinnamon 64bit). Being a newbie, I recently came across something I don't understand. I want to use the :vimgrep and :grep ...
2
votes
1answer
46 views

Shutdown script seems to be executed twice

I have a small backup bash script that I wrote for my computer at work. I have copied the script into /etc/rc0.d/ and called it K01backup so it is executed before anything else upon shutdown. It backs ...
2
votes
2answers
52 views

Autocomplete of a file name in bash prompt

I usually put a date before a file or directory name similar to 2014-04-20 file_name.doc. So, in a folder there is usually a bunch of files and directories starting with a date. But when accessing ...
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 ...
1
vote
6answers
125 views

How to convert dashed string to spaces and caps?

Given the string foo-bar, what is a good way to convert it to Foo Bar? Using Bash, OSX.
2
votes
3answers
153 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
49 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 ...
6
votes
4answers
308 views

How to split text between separator into multiple files?

I have a text file contaning the following: "random textA" "random random textB" The separator is " How can I split the containt into multiple file as follow using a bash command? File 1 : ...
1
vote
3answers
48 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
384 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 ...
2
votes
0answers
34 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 ...
4
votes
2answers
165 views

Print repeating pattern

I have a marathon file from which I want to print the names of the runners, who have made multiple runs. Something like: M, 2:08:58.0, John Lukas, USA, 1997-07-25, Paris, France F, 2:15:04:0, Abebbe ...
1
vote
1answer
26 views

Exporting Variables from Read

I'm asking the user to input some data using Read that data will be save on a variable that is going to be use in another shell script. However, for some reason is not working. This is what I got in ...
1
vote
1answer
48 views

How to find strings using regular expressions in grep

So I have a file list with list of the people in a company. Each line contains Position(a short string), years, name(first and last), salary and nationality(three capital letters). They are divided ...
2
votes
2answers
50 views

“If variable does not contain” not working

This is my script if [[ ! $url == *.txt ]] then exit fi I have also tried: if [[ ! "$url" == *.txt ]] then exit fi and: if [[ "$url" !== *.txt ]] then exit fi But even though $url does ...
3
votes
2answers
45 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 ...
8
votes
1answer
198 views

Resume a suspended process in a for loop

I am running in bash: for i in ull-*.pbm; do convert $i tmp2/$i.pdf ; done I Ctrl-Z in the middle of running, and then fg its job id. But the remaining iterations do not continue to finish. I ...
2
votes
2answers
76 views

order for listing files

If I have a list of files under a directory ullman-000.pbm ullman-001.pbm ... ullman-098.pbm ullman-099.pbm ullman-1000.pbm ullman-1001.pbm ullman-1002.pbm ullman-1003.pbm ullman-1004.pbm ...
1
vote
1answer
48 views

substitute complex text string in several files that contains special characters

I need to replace a complex string in several files in a directory. The string that needs replaced is: ...
0
votes
3answers
37 views

Cannot prompt user using rm bultin prompt option -i with xargs and find

I am using xargs and rm with find in order to remove files that follow a specific pattern defined by find as follows. touch file find . -name file | xargs rm Everything works fine with the above ...
2
votes
2answers
68 views

How to create an alias to the directories and copy one file to another?

I want to copy a file from /home/e_empid/file1 to /home/e_empid /dir1/dir2/dir3/Backupfile1. User does not want to write a long command each time. Write a command to set an alias for above action? I ...
2
votes
2answers
86 views

Use Netrw or Nerdtree in Zsh/Bash to select a file BY BROWSING?

Often I find myself in the shell, wanting to insert a filename into a lengthy command. I'd like to hit a shortcut, and use Netrw or Nerdtree to browse for a file or directory, and have it pasted in ...
0
votes
0answers
31 views

deleting admin directory after deleting an admin user

I am creating Admin accounts using this command, sudo useradd *new-admin-username* -s /bin/bash -g sudo -m It creates the admin's directory in the /home/.. Moreover, since these are admin, I can ...
0
votes
1answer
25 views

Video-inverting my bash prompt

This is my prompt, as specified in ~/.bashrc: export PS1="${debian_chroot:+($debian_chroot)}\[\033[01;35m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ " ...that yields something like: I ...
0
votes
2answers
24 views

find parent string based on regex

No sure if I can do this easily but: I have a file like VDS|name=vds01|another_parameter vol=disk01|parameter|dev=/dev/dev/my_dev1|parameter_A=some_value1 ...
0
votes
1answer
36 views

How do I escape quotes for json conversion in Bash

I have a file which I need to convert to a json string and it needs to be done via bash. My test file looks like 1 2 ' 3 4 Here is what's happening $ LOG=$(cat file) $ printf '{"log": "%q"}\n' ...
8
votes
3answers
189 views

How can I run a command in bash after any change in $PWD?

zsh provides some nice hook functions, including chpwd for running a function after the user changes directories. # zsh only function greet() { echo 'hi'; } chpwd_functions+=("greet") cd .. # hi ...
4
votes
3answers
162 views

Copy a specific percentage of each file in a directory to a new file

For example, we have N files (file1, file2, file3 ...) We need first 20% of them, the result directory should be like (file1_20, file2_20, file3_20 ...). I was thinking use wc to get the lines of ...
0
votes
1answer
33 views

Problem with bash syntax on command line

I'm trying to test a simple if statement by running it from the command line but bash wont run it. add a variable ~$ myVar = 23 run a conditional statement ~$ if [$myVar -eq 23] then echo "myVar ...
2
votes
1answer
32 views

How to associate exstension with program so that it works with tab complete

I use texmaker to edit my LaTeX (.tex) documents. I also use texmaker for other things, but 90% of the time I just want to open a .tex document. If I want to open document.tex, I usually just write ...
4
votes
2answers
164 views

grep for repeated values from pattern list

I have file A.txt which is a lists of unique ids (column 1) and its corresponding values(column 2): A.txt ABC1D_T1_B1 123.4 ABC2D_T1_B2 146.7 ABC3D_T1_B1 567.8 ABC4D_T0_B2 96.8 ABC1D_T0_B1 ...
1
vote
0answers
53 views

Bash script run file redirect the license and difent key press to a dialog graphic tool

i am trying to show the license from the ".run" script file in specific , the "TeamSpeak 3 Client" .run , file I am trying to make this with "zenity" , "mate-dialog(s)" and "kdialog" ok right now i ...
0
votes
3answers
107 views

Shell script to add or replace block of text?

I'm looking for a shell script (Bash) that adds or replaces copyright text at the beginning of the file (for .c and .h files). It should search and add or replace the copyright text block for all the ...
2
votes
7answers
216 views

How to print lines with blank 5th field in CSV

I have to check if the fifth field is empty in a CSV file. This is my file: 1,abc,543,87,DATA,fsg; 1,abc,543,87,,fsg; 1,abc,543,87,DATA,fsg; 1,abc,543,88,,fsg; 1,abc,543,,DATA,fsg; As you can ...
0
votes
0answers
17 views

Get CPU time for Benchmark in Bash Script

I'm using this Method here: http://giantdorks.org/alain/how-to-benchmark-individual-shell-script-sections-to-identify-slow-parts/ to Benchmark my Bashscript: RuntimePrint() { duration=$(echo ...
0
votes
1answer
18 views

Confusing db2 output

When type in echo $(db2 -x "select count(*) from dict_area") in bash, I get 446. But when I type in echo $(db2 -x "select count(*) from dict_area";db2 -x "select count(*) from dict_area"), I get ...
11
votes
5answers
1k views

Shell: “Display all 2588 possibilities?”

So, I was moving my laptop around (and I have the bad habit of setting things on the keyboard...) and I woke up to discover this: $ Display all 2588 possibilities? (y or n) What command would ...
6
votes
4answers
375 views

Detect if a variable is empty

In my Bash script I have this line: mv -f $HOME_DIR/$dir $HOME_SAVE/BACKUP The problem is when $dir is empty (no $dir directory) the mv command moved the directory $HOME_DIR. We want only to move ...
5
votes
2answers
57 views

Long-generating Bash prompt wraps incorrectly when I start typing

I have a Bash prompt that takes a while (~100-200ms) to generate, because it includes Git working tree status that takes some time to compute. Sometimes I start typing a command before it appears, but ...