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

Unix: Bash Limiting Output to X Amount of Lines

I am trying to modify a script so that it will truncate the output that goes to another file to a maximum (for example: 1000 lines). I have read about split, but what I understand is that split by ...
0
votes
0answers
1 views

Setting up a script on an AMI box to create directories - vsftpd, pam, mysql

I'd like to first say I'm a noob when it comes to linux, so please excuse my confusion. I'm trying to setup vsftpd on a amazon ami 64 bit box, free tier micro. Following these instructions, ...
1
vote
2answers
33 views

How do I use a function return as a condition of an if else then shortcut?

There are instances where a function needs to execute and return to the caller and this works for me. if tst; then echo "success" else echo "failure" fi function tst () { return 0; } ...
1
vote
0answers
6 views

java version not found in redhat

My OS is redhat linux. It's having the default java 1.4.2, but I need java 1.7.45, for that I am trying as follows: /usr/sbin/alternatives --install /usr/bin/java java /u01/java7/bin/java 5 ...
2
votes
3answers
72 views

Loop over associative arrays by substring

In the following code, I create some associative arrays in a loop. The consist of two strings, a string identifier and a year. After creation, I want to access the arrays in a loop based on the ...
0
votes
1answer
20 views

Locate specific file from script

I've written a script file in which, one function searches for another script and if found, executes that script. Script extract #!/bin/bash ... service_status() { local my_script=`which ...
0
votes
0answers
8 views

Strange characters in GIT completion

I'm running bash GNU bash, version 4.3.25(1)-release (x86_64-apple-darwin13.4.0) on OS X 10.10.1. A week or so ago I've noticed that autocompletion has stopped working, but only for git. I'm ...
1
vote
1answer
19 views

Broken git autocompletion after I have overridden the git command

Recently git branch <tab> started showing me the following error: $ git branch bash: -c: line 0: syntax error near unexpected token `(' bash: -c: line 0: `/usr/bin/git --git-dir=.git ...
-1
votes
1answer
23 views

Error while running script with nohup

I got this error while running my script with nohup sh: syntax error near unexpected token `(' My script is as follow: #!/bin/bash report_log="report.log"; grep -A 3 'successful\|ERROR COUNT ...
0
votes
2answers
34 views

script that lists all files in a directory and subdirectories sorted by size, listing only file names not complete paths

I'm looking for a script that lists all files in a directory and subdirectories sorted by size, listing only file names not complete paths. find . -type f -exec ls -lhS {} \+ works but gives the ...
5
votes
1answer
28 views

Using process substitution to trick programs expecting files, with specific extensions as argument?

Here is my use case: the command line utility melt can accept a file name, with the extension .melt on the command line, and open it; as an example, this is a proper test_p.melt file: colour:blue ...
2
votes
2answers
31 views

how to workaround a deadlock (multithreading a program)

I need to run a program 100 times, a few hours each, which is fine when running it in a serial way, just takes very long, but when I try to parallelize it using GNU parallel or simple '&' in bash, ...
-5
votes
2answers
34 views

placing things in a users home directory with .deb

i am making a .deb installer and would like to place some files in the users home directory but i can not hard code a username. does any one know of any other places in the file system that i could ...
0
votes
1answer
34 views

finding and replacing text [duplicate]

Does any one know how to find and replace text in a file. it can be implimented into a bash file. i would like to find the line and the output the text to it the file can only be opened with the root ...
0
votes
0answers
12 views

bash/svn how to filter documents [on hold]

Does anyone know how to filter documents. For example, if I had something like this: dVa/Prs/Upe/dVar.var I want to only the last file in log and then add to this file another for example after ...
0
votes
1answer
16 views

Unix: Looking to run a script in directories with a certain name

I am writing a script in bash. If I am in directory Foo, I want to run this script in only the subdirectories of foo that are named foo with up to three numbers after foo. Ex: foo1, foo23, foo345 ...
2
votes
1answer
57 views

Bash: command substitution with multiple unset/export commands

I am trying to unset some variables and export others using command substitution. This works: $(echo " export TEST_A=1 export TEST_B=2 ") And this too: $(echo " unset TEST_A ...
3
votes
3answers
66 views

The output I get via “echo” works as a command when pasted to terminal, but not in the script

I'm trying to change the files generated by an app that unfortunately often contain spaces. I have managed to get "echo" to give me output that works if copy pasted into terminal, but when I try to do ...
0
votes
2answers
27 views

Command substitution and spaces

Why does this work as a calculator: [root@qabun02 ~]# echo $(( 5+2 )) 7 but this doesn't? [root@qabun02 ~]# echo $( (5+2) ) -bash: 5+2: command not found The only difference I can see is the ...
0
votes
1answer
17 views

Bash script: array elements containing space character [duplicate]

I'm getting started with bash scripting. I'm working with array elements that contain space characters. In the code below, the third array element is "Accessory Engine". I tried to set the space ...
1
vote
1answer
73 views

Why does the printf statement in this loop output the array out of sequence?

When I execute the following code, the output of the printf statement appears to show array out of sequence. In the declare statement the Source item is declared before Destination and in the output ...
3
votes
1answer
47 views

Can I run a command loaded from .bashrc with sudo?

I have some custom functions and aliases defined in my .bashrc file. Sometimes I need to execute whem as root. I then do something like: $ sudo custom_cmd 80 ...
0
votes
2answers
55 views

How to convert Log file to CSV using bash

Is it possible to turn this log entry into a properly formatted csv file using sed/awk? I've tried multiple ways to do this using sed/awk. Alas I couldn't do it. Before I do it in perl. is this ...
2
votes
3answers
59 views

How to get tab completion when using curly braces in Bash

I want to have tab completion when using curly braces in a command in bash. For example: cp ~/html/{foo bar.txt whatever} /var/www/html/ I want the tab completion for the files stated in the curly ...
2
votes
3answers
70 views

Using find with 2 sets of variables

I want to be able to run a find command in my bash script that will find files based on two seperate variables. I've gotten this far but I'm not sure how to get the final result workingfind . -user ...
0
votes
2answers
49 views

Untar and gzip from multiple sub directories

I have a directory which consists of multiple sub-directories. Each subdirectory has a tar.gz file which on untar gives two files namely R1.fastq and R2.fastq. I want to untar the tar file and ...
0
votes
1answer
28 views

Opening a socket in Kali Linux using bash scripts

I know how to open a TCP or UDP socket in Ubuntu, with the following command : exec 3<>/dev/tcp/google.com/80 for example: we can open a TCP socket on port 80, but in Kali Linux there's no ...
1
vote
1answer
41 views

Read a character from an x-y coordinate on the screen

Is there a way in bash to read a character from an x-y coordinate on the screen? This command would be something similar to cget 12 30 which would return the character at the 12th row and 30th ...
0
votes
2answers
22 views

redirect output from interface?

I am echoing an AT command to a modem interface (/dev/ttyUSB3) and the command runs successfully. For instance the below command works and has an output of OK: echo -e "ATZ\r" > /dev/ttyUSB3 I ...
0
votes
2answers
19 views

The best way to add Unix Shell variables to CURL GET request

Let’s say I use curl –X GET command with the following link: “$WEBSITE_URL/ACTION_NAME/ACTION1;id=$ID?Command=TEST&id1=$ID1&id2=$ID2&id3=$ID3” As you can see, there are some $variables ...
0
votes
1answer
26 views

I don't see .bashrc file in my /home and /etc/skel direcories

I am running linux mint 17.1 rebecca, but I have found it quite different with other distros I am used to, in /home and /etc/skel there's no .bashrc I don't know if i mess up with something or it is ...
0
votes
1answer
18 views

Tar Create and Split files into subdir

I have this command: tar -cf - input/* | split --bytes=1m Which splits my huge gz files into small ones. This works fine. However I want the output (the small files) to be created in the input/ ...
0
votes
1answer
12 views

Universal .bashrc alias showing results of sysytemctl start command

This is small .bashrc alias that allows me to see results of starting service alias systemctl start apache='systemctl start apache && echo SUCCESS || echo failure' How can i modify to work ...
1
vote
2answers
35 views

Do programs source .bashrc when run?

I append to my PATH environment variable in my .bashrc file (Ubuntu v12). I also have a service (Atlassian Bamboo) that relies on the modifications to PATH. When I restart the service (which runs as ...
2
votes
2answers
55 views

Using the output of `grep` as variable in second command

I currently have 2 bash command line strings I use to gather data needed for a certain task. I was trying to simplify and have only one command used to gather the data without using a script. First I ...
2
votes
1answer
16 views

Is there an alternative to using rbash to restrict a user on my system?

Basically at the moment I am using rbash to stop a user from leaving his directory on my system. The problem with this is, there is a script in my bin which he needs to be able to run from a script in ...
1
vote
2answers
50 views

ls .. doesn't work properly with symlinks

I have directories set up a bit like this ~/code ~/code/src ~/code/build -> /path/to/somewhere/else That last one's a symlink. If I do this cd ~/code/build ls .. then I get the listing for ...
1
vote
3answers
207 views

How to copy files from the folder without the folder itself

I'm trying to copy files and subfolders from A folder without the A itself. For instance, A folder contains next: | file1.txt | file2.txt | subfolder1 Executing next command gives me ...
8
votes
2answers
413 views

Run another command before running the command the user wants to run

Let's say I want to modify the original behavior of the ls tool this way: $ ls Hello World file1 file2 ... How can I do this? When running ls I would like to run another command let's say echo ...
11
votes
3answers
582 views

Terminal vs bash? [duplicate]

I'm on a Mac but I think this is generally Unix-applicable. I'm in the process of learning shell scripting and there's something I seem to be missing. When I'm in the ordinary terminal, I can use ...
1
vote
1answer
49 views

bash - command not found [on hold]

I have a script [pic@pic Desktop]$ cat skrypt.sh #!/bin/bash awk '{sub(/#echo "Wstałem"/,"#echo \"Wstałem\""); print $0 > "skrypt.sh"}' skrypt.sh awk '{sub(/awk/,"#awk"); print $0 > ...
1
vote
3answers
28 views

Loop to check whether a Debian package is installed or not

I like to check whether several packages are installed or not on Debian/Ubuntu Here is my attempt at a script to do this: query=`dpkg-query -W -f '${Status}'` ok="install ok" if ! [ `$query` curl ...
1
vote
1answer
51 views

Example for adding

Example 1. Adding to the console works well pic@pic:~/Desktop$ a="$(date +%s)" pic@pic:~/Desktop$ b="$(date +%s)" pic@pic:~/Desktop$ echo $[a+b] 2844184057 pic@pic:~/Desktop$ Example 2. It's the ...
1
vote
1answer
28 views

Sourcing a redistributable script by default

I am creating a bash script which I wish to release on github. The script needs to access the command history but this is not possible without sourcing that script. I don't want users to put it in ...
1
vote
1answer
43 views

How to execute 'clear' bash command before any other command is executed?

I see the question at Can I configure bash to execute "clear" before every command typed in the console?, but the answers there are not valid for GNU bash, version 3.2.53(1)-release ...
1
vote
2answers
46 views

BASH: Command not running, special character '�' suddenly appeared (Ubuntu)

When I erroneously type 'ñ' (expecting to type any command) and then remove it and type the correct letter, the output returns the command with a special character attached �, obviously the shell ...
4
votes
2answers
158 views

Appending works without >> when redirecting standard output and error

I have a file test.txt and have no file named test. When I tried ls test test.txt > new 2>new I was expecting new to be overwritten since >> is not used. But in the output file I got ...
0
votes
0answers
13 views

Escape ampersand in bash variable used as a sed argument [duplicate]

I have a template Hello NAME welcome and want to replace NAME with data like "Judy&Mary". Why does this not work? TEMPLATE="Hello NAME welcome" DATA="Judy&Mary" echo $TEMPLATE | sed -e ...
1
vote
2answers
48 views

Read line from file then delete

How can I read a series of lines from a file and then remove each line? Obviously I can read like this: while read -r line; do echo $line done < myfile.txt But if I do this: while read -r ...
-1
votes
1answer
23 views

Check exist file on another pc

Yesterday I had ask how to use my tftp protocol in my bash script: Debian - Using TFTP in a bash script And now I have a problem with my tftp protocol. The file who was taken depend of my Hostname. ...