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
2answers
32 views

How to make backticks accept variables as variables?

This is my code: #!/bin/bash machine_we_are_looking_for=$1 user_defined_new_machine_location=$2 condition_while_one=true condition_while_two=true echo "test 1" while $condition_while_one do ...
0
votes
0answers
7 views

Google Chart - Using Bash to dynamicaly add data - collected from a MQTT stream

I can collect data from the MQTT stream, I was curious to know 'how' I can push this data dynamically to the Google Charts with BASH/Shell script? This script will eventually be running daemon ie 'run ...
0
votes
1answer
52 views

Temporary file BASH

does this piece of code creates temporary file? Because I am not supposed to use them and I only found out yesterday that even sed -i creates it. So I can be sure. Thanks while read line; do if [[ ...
1
vote
0answers
22 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=.stage_rsync_rules ...
2
votes
2answers
19 views

Can someone explain exactly what is happening with single quotes and double quotes with process IDs in the below example? [duplicate]

[root@localhost ~]# echo $$ 16991 [root@localhost ~]# bash -c "echo $$" 16991 [root@localhost ~]# bash -c "echo $$" 16991 [root@localhost ~]# bash -c 'echo $$' 21062 [root@localhost ~]# bash -c 'echo ...
2
votes
2answers
69 views

How to remove duplicate files using bash

I have a folder with duplicate (by md5sum (md5 on a Mac)) files, and I want to have a cron job scheduled to remove any found. However, I'm stuck on how to do this. What I have so far: md5 -r * | ...
1
vote
1answer
43 views

Why are files and directories colored in different ways? [duplicate]

On Ubuntu 14.04, in bash under gnome terminal, Why are files especially directories colored in different ways? The green colors hide the text to me (How about to you?). Is it done by terminal or ...
0
votes
0answers
24 views

Would this command delete only the lines containing specific words within a delimited area? [duplicate]

Please see my previous question here. No one seems to be following up on it, so I have tried to have a go myself: sed '1 { /^---/ { :a N; /\n---/! ba; /^Title: \|^Place: /d} }' filename Would this ...
10
votes
7answers
488 views

In bash .* equals to upper directories

Someone of our team wanted to recursively change the user permissions on all hidden directories in a users home directory. To do so he executed the following command: cd /home/username chown -R ...
0
votes
0answers
49 views

Combine lines of file to string [on hold]

I am trying to have a file inputted by my script and put into a string to be put into another file. ./script.sh -u uuids.txt -s servers.txt Each file will have a list with each value being on it's ...
0
votes
0answers
47 views

Replace a string with another string in a text file [on hold]

I want to replace a string that is in the file file1 with another string. I tried sed -i -e "s/chaines1/chaine2/g" file1 but the problem is I can't pass the two strings on the command line ...
2
votes
3answers
46 views

What happens if I pass too few parameters to a shell function?

I would like to ask about passing parameters into functions. I tried this: function_name $var1 $var2 but usually (sometimes it printed error) it didn't make any difference whether I passed them or ...
2
votes
1answer
33 views

Can I re-login a disconnected session? [duplicate]

For some network reasons, my previous SSH sessions to server have disconnected. When I create a new session, I find the previous session still exist: [root@localhost ~]# who root pts/0 ...
3
votes
1answer
29 views

how to send output of curl request to 2 separate commands

I'm piping the output of a curl request to gawk so that I can pull some data. The gawk code is already working if I'm searching through the html file which curl request produces. However, I was ...
2
votes
3answers
52 views

One-liner for getting an IP address of an internal DNS name?

I have an internal DNS name for which I'd like to get the IP address. Is there a nice Bash one-liner I can issue to convert internalip1.mydomain.com into 10.10.10.10?
2
votes
1answer
89 views

grom() keyword in bash throws unexpected '(' token

I'm not entirely sure why I'm getting the error in my .bash_profile syntax error near unexpected token `(' when I use the keyword grom() for my function. I wanted to create a bash function that ...
4
votes
1answer
71 views

Can 'ssh <host> <command>' be configured to always load server-side startup files?

I would like run remote ssh commands and have them always load server-side startup files by default. I am looking for a solution that does not require: configuration by root adding extra boiler ...
1
vote
2answers
41 views

Remove paragraph from file

I have a file (file.php) like this: ... Match user foo ChrootDirectory /NAS/foo.info/ ForceCommand internal-sftp AllowTcpForwarding no GatewayPorts no ...
1
vote
1answer
52 views

Brace expansion not working in a script

for i in {1..40} do echo $i done I got {1..40} and I would like to have something like 1 2 3 and so on so I can use the variable i inside a command's parameter.
0
votes
1answer
35 views

User Input Bash Script

I am trying to make a Bash Script that has 4 choices and prompts the user to select an option. Each option corresponds to a Linux Command operation. Can someone give me a bash example on how could ...
0
votes
4answers
58 views

Copy same specific parts of a file to another file

How can I copy same specific parts of a file to another file? In the first file, I have: user01: Id name nationality user02: Id name nationality . . . I want to copy each piece of information to a ...
1
vote
2answers
28 views

Bash autocomplete: does not list files or directories

In my bash terminal, I would usually press tab twice to get the file and folder list. For instance cat 2XTAB would list all files and folders in the present directory and cd Proj2XTAB would list all ...
2
votes
1answer
35 views

How to verify the target of a symbolic link points toward a particular path

Within a bash script, I know I can check if a file is a symbolic link with the following syntax if [ -L $path ] Does any one know how I would test if that path was linked to a particular path? E.g. ...
0
votes
0answers
33 views

Compare specific word counts without variables or expr

I am tasked to write bash command to count number of specific words (given in file) in 2 files and write an error message if number of these words in first file is more than 3 times biggen than in the ...
0
votes
0answers
27 views

How to get and print a user's public IP address in a Shell Script? [duplicate]

I've just completed a lengthy installation script that deploys a Ruby on Rails application unto web servers. At the end of this script, I'd like it to print something along the lines of: "Installation ...
0
votes
0answers
16 views

MYSQL dump of tables that start with docs_ from one server to another

The headline says it :) I would need script that dumps all tables from 'ads' database on different server(s2) starting with 'docs_' copied to my server(s1). Any hints? The reason that I need script is ...
1
vote
1answer
30 views

Search for text inside java command output

I have a folder which have multiple Jar files. * dummy.jar * myjar-xx.jar * myjar-yy.jar Using find, I need to find first file starting with "myjar" Now, I want to grep the contents of ...
4
votes
1answer
44 views

Why does 'jobs' always return a line for finished processes when run in a subshell within a script?

Normally, when a job is launched in the background, jobs will report that it is finished the first time it is run after the job's completion, and nothing for subsequent executions: $ ping -c 4 ...
2
votes
0answers
24 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 ...
1
vote
1answer
33 views

How does 'bash' or 'gnome-terminal' print user and path information? [on hold]

I am wondering if there is a different mechanism between printing user and path information(e.g. "guest:~/home/guest$") and command outputs. When I try to PIPE stdin and stdout of "bash", I can only ...
2
votes
0answers
28 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 ...
1
vote
1answer
42 views

Printf formatting with variable format - what does this var reference?

I am experimenting with printf formatting in bash and I ran across this piece of code: #/bin/bash divider=============================== divider=$divider$divider header="\n %-15s %8s %10s %11s\n" ...
2
votes
2answers
78 views

How to print from a given range of ip addresses every class-c with the last octect replaced by an asterisk

example: I have a range from 10.0.100.0 to 10.0.224.0 and I want the output like this: 10.0.100.* 10.0.101.* 10.0.102.* and so on
5
votes
2answers
436 views

Why doesn't $@ work when passing strings?

For example, using this script: #!/bin/bash for a in $@ do echo $a done And running:./script "x y" z returns: x y z and not: x y z Why is that? And how would I pass string arguments with ...
1
vote
1answer
52 views

cat .bash_history | grep ./configure [on hold]

Why does this not give any output: cat .bash_history | grep ./configure on an system/in an shell where ./configure has been run multiple times. And if I use the arrow key's to scroll the history in ...
0
votes
1answer
17 views

Execute a program from the bash terminal without waiting for program to close [duplicate]

Executing a program in the terminal with a command such as ./theprogram runs the program, but waits until the program closes. This is useful if you want to see the output of the program, but what if ...
-1
votes
0answers
24 views

Using a function within MySQL update [on hold]

I've got a code snippet: #!/bin/bash timestamp() { date +%s } . .//some code here . data_base="UPDATE ... SET last_update_time = 'timestamp' WHERE equip.title = '$equip_title';" . .//some [more] ...
4
votes
2answers
54 views

Coming back to a command I have partially written [duplicate]

Often I find myself partway through writing a long command (or chain of commands) and realise I need to run another command before I can finish typing out this current one. Examples Sometimes, I... ...
1
vote
2answers
206 views

Why do I have double slash here?

$ which mycommand /home/t/program_files/document/other edits//mycommand Why do I have double slash // here?
1
vote
1answer
31 views

Using parameters in a script

I usually use the find command to automatically copy certain multimedia files from directory A to directory B. I use the following command: for f in `find ./ -name "*.mkv" -mtime -24h`; do cp $f ...
0
votes
1answer
44 views

Double quotes in bash

I am trying to create a bash file which calls a program that expects a parameter to submitted between two double quotes. Take a look at my file content. #!/bin/bash echo ./yowsup/yowsup-cli demos ...
1
vote
1answer
24 views

decrypt and unarchive file embedded in the script

I'm trying to create a self-extracting encrypted archive. Here's code that doesn't work for me: openssl enc -aes-256-cfb -salt -d -a | tar -x -j <<EOF ...
1
vote
1answer
20 views

Sort packages by size one-liner as function

While surfing web I've discovered nice one-liner that suits my needs well expac -s "%-30n %m" | sort -hk 2 | awk '{print $1, $2/1024/1024}' | column -t| However all the functional needed I got used ...
-1
votes
1answer
29 views

AWK and Bash Scripting [duplicate]

How to use a value of a variable in awk? Something like this: filename = "test.txt" ls -l | awk '{ if ($9 == filename) print("File exists")}' I can't use $ in awk to access the value of ...
5
votes
1answer
107 views

using ! character in echo

I am messing with echo and having issues with echo displaying the ! character. I tried this. echo -e "Wake!\nUp! bash: !\n!: event not found Then this # echo "Wake\!\nUp!" Wake\! Up! Well now ...
4
votes
2answers
154 views

Using bash's `/dev/udp`, how would I know if the port was open?

I do not have access to netcat or nmap so I'm trying to use bash and the /dev/udp/ special files to test ports. I could do something like: echo "" > /dev/udp/example.com/8000 But $? is always 0 ...
0
votes
1answer
42 views

i don't know what's wrong with the code below. it says 'unexpected end of file' [closed]

export FF=../list3.faults export CIR=../b22_opt_C.bench if [ -e redun ] ; then rm redun fi date > opendate ./atalanta -u -U redun -t .test1 -f $FF -b 1 -B 1 $CIR > text; date > ...
2
votes
3answers
28 views

Rename multiple files to their suffixes

I need a way to rename a couple of files containing spaces. I have: >ls Garbage Foo1.txt Garbage Foo2.txt Garbage Foo3.txt Garbage Foo4.txt ... And I need: Foo1.txt Foo2.txt Foo3.txt Foo4.txt ...
2
votes
1answer
47 views

bash ssh warning when connect to raspberry: setlocale: LC_ALL: cannot change locale (en_US.UTF-8) [duplicate]

I tried for example this to solve my problem and this too. My problem is that when I try to connect to my Raspberry pi2, I got the following messages: Linux raspberrypi 3.18.7-v7+ #755 SMP PREEMPT ...
2
votes
2answers
85 views

How to delete old backups based on a date in file name?

I have a daily backups named like this: yyyymmddhhmm.zip // pattern 201503200100.zip // backup from 20. 3. 2015 1:00 I'm trying to create a script that deletes all backups older than 3 days. The ...