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
35 views

Split the large files into sub files. How to do this process? [duplicate]

I have a large file in my unix box with 2 Gb. The files contains the xml lines. I want to split the files into say 10 files say each file is now of 204 MB ( approx ) so that combining the 10 files ...
9
votes
2answers
517 views

How do I force a user to change a password at the first time login using ssh?

I'm trying to force a newly created user to change a password at the first time login using ssh. For security reasons I want to give him a secure password until he logs in for the first time. I did ...
2
votes
1answer
15 views

How to make PATH variable exports on MacOSX persistent?

I do export http_proxy=http://proxy:8080 export ALL_PROXY=$http_proxy on my Mac. Brew for instance relies on these settings. How can I make these settings stick between power cycles? Is this the ...
4
votes
2answers
42 views

Is there a way to have a function in my bash script auto run on any command error?

I'm writing a shell script that needs to do a bunch of commands and every command depends on every previous command. If any command fails the entire script should fail and I call an exit function. I ...
0
votes
1answer
12 views

Linux bash commands in android 4.1.2?

Is there a way to run linux bash commands in android (particularly 4.1.2 rooted or not rooted)? Will it void the warranty from phone manufacturers?
0
votes
1answer
24 views

How to monitor bunch of machines for CPU usage from another machine?

I have couple of machines as shown below which are running Ubuntu 12.04 and I need to find out the process name along with its pid whose CPU usage is greater than 70%. Below are the machines as an ...
1
vote
1answer
81 views

Storing longer text output in memory in shell variables vs Writing to disk

I have the below call to db2 command line tool inside a loop which runs 100k iterations. (the db2 output is 5 rows of 20 chars approx per each call, total of approx 100k calls. The input to SP is ...
1
vote
2answers
26 views

Parse command output [duplicate]

I want to only get the value associated to "cached" column of the free -m command. What is the most efficient way to achieve it? Something with sed or awk?
1
vote
4answers
260 views

Why does bash display `>` instead of executing my command?

Why does bash sometimes refuse to accept my orders by simply starting a new line beginning with a greater-than sign instead of executing the command? Every press on enter adds a new line, and the only ...
1
vote
3answers
39 views

check if all files from a folder are also in another folder

I basically have a directory a with lots of images. Now I want to check if all of these images are in directory b. The point is, that lots of images in b ain't directly in b but in subdirectories. ...
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
11 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
60 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
30 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
42 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
26 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
36 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
51 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
18 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
51 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
123 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
143 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
46 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
298 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
45 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
381 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
32 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
164 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
25 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
46 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
43 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
193 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
44 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
67 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
82 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
24 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
23 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
35 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
183 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
159 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
32 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 ...