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

sort process by cpu usage in cygwin

please help me to sort process by cpu usage in cygwin. I already tried tasklist but it shows only process by memory usage .
1
vote
0answers
14 views

Why does history not overwrite but append when histappend is set to off in Bash?

Several days ago, I had one Terminal tab doing ssh, and the other doing a lot of work locally. And then I restarted the machine (on a Mac with Mavericks). When I ran Terminal again, I found that all ...
3
votes
2answers
31 views

process Count of each user in ps aux command

How can i create a script to count process run by each user in ps aux. I used this ps aux | awk '{print $1}' | grep root | wc -l but it lists count of root user only . I want to list number of ...
1
vote
4answers
685 views

Inserting the command line text before output in stdout (for pipe / redirection)

Consider the following bash constructs: ls /usr/include/asm > list-redir.txt ls /usr/include/asm | tee list-tee.txt In this case, list-redir.txt and list-tee.txt will be identical, and will ...
4
votes
3answers
74 views

How to use call-by-reference on an argument in a bash function

I am trying to pass a "var name" to a function, have the function transform the value the variable with such "var name" contains and then be able to reference the transformed object by its original ...
1
vote
1answer
21 views

Can I uncompress a zip file containing a disk image and then save that to an SD card all in one step?

I am under the following restrictions: I have a 1.0 GB .zip file on my computer which contains one file, a disk image of raspbian. When uncompressed, this file is 3.2 GB large and named ...
16
votes
2answers
361 views

What does 'exec {fd}</dev/watchdog' do in Bash

That is literal, {fd} isnt a placeholder. I have a script that does this, and does not source in anything, nor does it reference {fd} anywhere else. Is this valid bash? exec {fd}</dev/watchdog
17
votes
9answers
13k views

Text processing - join every two lines with commas

I have more than 1000 lines in a file. The file starts as follows (line numbers added): 1. Station Name 2. Station Code 3. A N DEV NAGAR 4. ACND 5. ABHAIPUR 6. AHA 7. ABOHAR 8. ABS 9. ABU ROAD 10. ...
3
votes
1answer
26 views

Notification Listener Behaving Strangely when Backgrounded

I've been struggling to get my IRC-Bouncer/Notification Script working. This is meant to be a script which will automatically login to a remote machine, attach to a screen session (or start one if ...
2
votes
5answers
267 views

Get very next word of a substring in a string

I need to get the next word of a word in a string. I tried to write a script but it's not working. And it's good if you suggest me any other alternatives to achieve this. Script: #!/bin/bash ...
4
votes
4answers
333 views

$@ except the 1st argument

I need to write a shell script that runs in this way: ./myscript arg1 arg2_1 arg2_2 arg2_3 ....... arg2_# there is a for loop inside script for i in $@ However, as I know, $@ includes $1 up to ...
3
votes
1answer
208 views

prevent a command from sending both stdout & stderr to any terminal or file [duplicate]

I would like to prevent my program from sending stdout and stderr to any terminals, files or devices. For this, I have three command crossing my mind, but I cannot distinguish their differences. Could ...
1
vote
3answers
33 views

Select and sort IP address keeping the whole line

So I need to sort the IP Addresses and then sort my line by them. I can sort IP addres in a file by using : sort -n -t . -k1,1 -k2,2 -k 3,3 -k4,4 If my file looks like : add method1 a.b.c.d ...
14
votes
4answers
14k views

How can I tell what command an alias stands for?

ll is a common alias in many Linux distros. How can I tell what it aliases to? I've tried checking my .bashrc, but I am not able tell what ll is equivalent to.
1
vote
5answers
104 views

lines to columns with awk

I have to following sample output: <HARDWARE> <NAME>WIN1</NAME> <OS>Windows 7</OS> <IP>1.2.3.4</IP> <DOMAIN>contoso.com</DOMAIN> ...
0
votes
2answers
32 views

Different behaviour of eval “ command \”$@\“ ”, “$@”, and “$(echo $@)” when used as arguments [duplicate]

I would like to pass multiple arguments to the Tor browser (firefox) programatically through a function arbitrarily entitled tor. This is so as to command tor search terms and voila! My search terms. ...
10
votes
1answer
112 views

Fastest way to delete duplicates in large wordlist?

I need to deduplicate a large wordlist. I tried several commands and did some research here and here where they explain that the fastest way to deduplicate a wordlist seems to be using awk. awk ...
3
votes
1answer
72 views

weird characters in bash shell

Sometimes when I use the rm tool or stat tool in bash shell I get following weird characters: root@server:~# rm -vr blah removed directory: �blah� root@server:~# Locale settings can be seen here: ...
-3
votes
1answer
40 views

How can i replace a specific string within a line inside a text file [duplicate]

$ cat text.txt my name is Steven my age is 10 i like dogs What command will be fitting so that echo "Kate" will replace Steven on text.txt?
2
votes
2answers
31 views

How can I send multiple options to one variable

I am running a loop for an array of variables that generates three more variables. i.e for foo in ${bar[@]}; do bar1=$(echo $foo | awk '{print$1}'); bar2=$(echo $foo | awk '{print$2}'); ...
1
vote
1answer
6 views

Outputting PID of Rails server(s) with ps aux | grep - breaks when put into an alias?

I'm trying to create an alias for an unwieldy command I'm using to output the PID and some other information about two rails servers I have running. When I simply run the command in terminal (over ...
1
vote
4answers
77 views

Last Working Day of the Month

#!/bin/bash #!/usr/local/bin #!/usr/sbin #!/usr/bin # Script to Check last working Day of the Month echo " Enter Month and Year :" read mon year cal $mon $year| egrep "28|29|30|31"|awk 'BEGIN { ...
2
votes
2answers
206 views

Setting environment variables with .bash_profile: only last export works properly

I am trying to export some environment variables in Unix using .bash_profile It reads now like this: export PATH=${PATH}:/usr/local/cuda-6.0/bin/ export ...
6
votes
3answers
600 views

bash: escape individual lines from `-x` echoing

In bash, when running with the -x option, is it possible to exempt individual commands from echoing? I'm trying to make the output as neat as possible, so I am running certain parts of my script in a ...
73
votes
4answers
75k views

Why do I need a tty to run sudo if I can sudo without a password?

I have configured sudo to run without a password, but when I try to ssh 'sudo Foo", I still get sudo: sorry, you must have a tty to run sudo. Why does this happen and how can I work around it?
1
vote
2answers
50 views

How to interrupt uninterruptible program?

If I run mysqld from the command line, it displays some startup messages, and then stops responding. It doesn't produce output, and ignores any input, and there seems to be no way to get rid of it. ...
1
vote
1answer
24 views

Starting in normal mode on bash

I was very happy to discover that I could use vi keybindings in the bash shell (bash vi mode). I am a little frustrated now however that the shell always defaults to insert mode rather than normal ...
0
votes
2answers
32 views

Insert text to file using bash scripts (NOT appending)

I want to add text to a file using shell-scripts. The solution I know is if you want to insert your text into a newline (appending): echo "mytext" >> myfile.txt what I want to have a ...
0
votes
1answer
2k views

LFTP mirror upload only non existing files to remote directory

Every 5 minutes some new files are downloaded via lftp to a local directory. I need to upload to another ftp only the non existing files. My script so far is: #! /bin/bash today=$(date +%Y%m%d) ...
2
votes
2answers
38 views

List transient files by numerical value having number greater than a given constantly varying filename

I've a directory having constantly changing filenames (by numerical value) listed as: -rw-rw----. 1 root root 10493952 May 7 10:39 A0000000.LOG -rw-rw----. 1 root root 10493952 May 7 08:38 ...
1
vote
1answer
18 views

adb pull not accepting a variable as source, gives *' does not exist..* error

I'm trying to use $EXTERNAL_STORAGE in the adb pull command. I noticed that the variable has its scope defined in Android only and so it would not work successfully in adb pull ...
1
vote
1answer
852 views

Run a command under sudo over SSH

I am accessing remote machine in Linux using Bash scripting.My code is as follows #!/bin/bash ssh -i manu_bp.pem ubuntu@54.68.67.68 <<EOF sudo -s cat ...
30
votes
2answers
2k views

Symbolic link recursion - what makes it “reset”?

I wrote a little bash script to see what happens when I keep following a symbolic link that points to the same directory. I was expecting it to either make a very long working directory, or to crash. ...
14
votes
11answers
47k views

Show sum of file sizes in directory listing

The Windows dir directory listing command has a line at the end showing the total amount of space taken up by the files listed. For example, dir *.exe shows all the .exe files in the current ...
0
votes
1answer
35 views

How to add a folder to a remote hosts PATH using a shell script?

I'd like to automate the process of syncing a local ~/bin folder to a remote host, and adding that folder to my remote shell's path. I've got the syncing part done, but am not sure how to automate ...
3
votes
1answer
148 views

Exit bash when find gets to a folder with permission denied

I'm trying to write my second Bash script. Where i go through folders recursively and make a list of and count files and folders. In a way it works but if "find" gets to a directory where it has ...
8
votes
3answers
34k views

How can I delete all files with a particular extension in a particular folder?

If I set the current/working directory (navigating to it using cd) to some particular directory and then type: rm *.xvg What will this command do? Is it true that the above command will only ...
31
votes
2answers
27k views

How to remove a single line from history?

I'm working in Mac OSX, so I guess I'm using bash...? Sometimes I enter something that I don't want to be remembered in the history. How do I remove it?
0
votes
1answer
34 views

How to add new column, where the value is based on existing columns with awk

I have a file of multiple columns. I would like to make an additional column based on the values of 2 columns from this file. Example input: A B C D E F 1 2 T TACA A 3 2 3 4 I R 8 2 9 3 A C 9 3 ...
3
votes
0answers
67 views

How to best track adventures of a novice administrator

I have this user that has limited sudo privileges, yet he manages to screw up from time to time. I would like to keep an eye on his adventures, so that I can reverse any damage with less digging. ...
2
votes
6answers
5k views

Bash eval array variable name

Here is my bash case: First case, this is what I want to do "aliasing" var with myvarA: myvarA="variableA" varname="A" eval varAlias=\$"myvar"$varname echo $varAlias Second case for array variable ...
6
votes
4answers
5k views

How to use a variable as part of an array name

I have two arrays: arrayA=(1 2 3) arrayB=(a b c) and I want to print out one of them using a command line argument, i.e., without any if else. I tried a few variations on the syntax with no ...
0
votes
3answers
48 views

How to execute source command from sh file

I have file called install.sh and within this file I write something to $HOME/.bashrc file and after that I must call source command. In terminal I can type source $HOME/.bashrc but I can't do this in ...
2
votes
4answers
6k views

Installing crontab using bash script

I have created a script to install two scripts on to the crontab. #!/bin/bash sudo crontab -l > mycron #echo new cron into cron file echo "*/05 * * * * bash ...
1
vote
1answer
36 views

Identifying duplicate fields and print both with awk

I have a file with multiple columns and want to identify those where specific column values (cols 3-6) have been duplicated. The following code finds the duplicates but I want to display both ...
2
votes
1answer
40 views

Is there any plugin for zsh or bash that does heuristic filename completion?

Such as if $ ls program_v1.21.rb program_v2.01.rb program_v2.01_final.rb so when I $ echo progv2fin[TAB] it completes to $ echo program_v2.01_final.rb Sure there must be something, but I ...
0
votes
2answers
37 views

How to store whole a paragraph as one element of array in bash script

I am using the following code to read data from a file abcd.txt and try to store in an array parameters, I am able to store 619617 in parameter[0] and update in parameters[1] but in parameters[2] I am ...
4
votes
3answers
245 views

how to prevent exported environment variables to be recognized/accessible by a child shell (bash)?

So, I need to prevent loads of exported variables to be recognized by a child shell. The problem is an application (Wine+UDK) wont build projects with too many (>65535) bytes on the environment, ...
1
vote
0answers
31 views

Debian Jessie, copy file on NFS share (autofs) at shutdown

I'm on Jessie 8.1 so I use systemd to launch a service at shutdown. My service uses a script to copy a file on a NFS share (mounted by autofs). It doesn't work, I know the script can copy a file on ...
0
votes
1answer
49 views

sed in while read loop doesn't complete commands

I have a test file called testPage with the following text: || '''Title1''' || '''Title2''' || '''Title3''' || || Cell11 || Cell12 || Cell13 || || Cell21 || Cell22 || || Cell31 || Cell32 || || Cell41 ...