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

1
vote
1answer
772 views

bash script select menu

I've many notes gleaned from the web and have written bash scripts to manage them. I've some scripts working that depend on select to make menus. Question: in a nested menu context, is it possible ...
1
vote
0answers
33 views

How to force bash to start at index 0 with select output?

Well, even some less-experienced bash users would know meanwhile about the fact that bash arrays would always start with index 0. However, select will always do its own thing, as the following example ...
0
votes
1answer
25 views

regexp in find to locate only

I have csv file (products.csv) with product numbers $ cat products.csv | head -3 2.20 2.21 2.22 in another directory I have thousands of product images in subdirectories. I need to locate product ...
4
votes
2answers
99 views

Why does my Python background process end when SSH session is terminated?

I have a bash script that starts up a python3 script (let's call it startup.sh), with the key line nohup python3 -u <script> &. When I ssh in directly and call this script, the python ...
0
votes
2answers
49 views

Bash getting integer expression expected

I have following script to check disk usage #!/bin/bash # set alert level 90% is default ALERT=10 OIFS=$IFS IFS=',' storage=$(df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " ...
0
votes
0answers
60 views

Strange bash sytax error depending on sudo usage

I made this bash function to detect if the user running is actually logged in as root user and not using sudo by checking the uid + home directory of the user executing the command: #!/bin/bash set ...
1
vote
1answer
50 views

How do I define alias with variables which can be changed at runtime?

This is probably a very easy to answer question, but I could not find any questions already asking this due to different wording when writing titles. Running help alias on my bash prompt returns only ...
6
votes
3answers
552 views

Terminal prompt not wrapping correctly

I have an issue where if I type in very long commands in bash the terminal will not render what I'm typing correctly. I'd expect that if I had a command like the following: username@someserver ...
6
votes
3answers
6k views

How to solve the issue that a Terminal screen is messed up? (usually after a resizing)

Sometimes, a terminal screen is messed up, and when we use man ls to read the manpages, or press the UP arrow to go to previous commands in history, the screen will show characters not as the right ...
1
vote
3answers
86 views

Add or subtract a number from the names of all the files in a directory

I have a number of png and jpg files whose names are numbers, e.g.0100.png, in a directory, How can I add 1 to their names, for example, to get 0002.png and 0003.png from 0001.png and 0002.png ...
2
votes
2answers
37 views

clipboard in bash

We can cut and paste current line in bash with ctl+u and ctl+y But I have read here that bash doesn't have clipboard concept, so how those shortkeys working? (or in another way: what they doing?)
0
votes
1answer
41 views

Diff: slightly different filenames, same file

I'm using diff -rq to compare directories on a Mac OS X 10.6 server. In folder1, we have 'filename'. In folder2, we have'filename.archive' because folder2 is created by a file sync app that also ...
0
votes
0answers
22 views

Bootstrap/Provisioning (bash)

While I know its not Craft related, I am going really really really ver very very mad about the following, which basically belongs to my craft setup... I am having a local bootstrap.sh script that ...
-1
votes
1answer
46 views

how to patch bash vulnerability (shellshock) bug on RHEL? [duplicate]

We have over 10000 servers to patch for bash vulnerability (shellshock) bug. Now my question is what is the command to patch this bug ? And how we can check whether the patch has been installed and ...
0
votes
1answer
30 views

Script a list of users who have been logged in for more than 24 hours?

I am attempting to create a simple script that will produce a simple list of users who are logged into a system for longer than 24 hours. I've seen the w command is good for being able to view idle ...
1
vote
1answer
35 views

Script to see if user has logged off

I have created this program to see if a user is logged on and it checks every minute. if [ "$#" -ne 1 ] then echo "Usage: mon user" exit 1 fi user="$1" until who | grep "^$user " > ...
4
votes
1answer
189 views

Why ZSH ends a line with a highlighted percent symbol?

I've noticed this on occasion with a variety of applications. I've often thought it was because the output was cancelled early (ctrl+c, for example) or something similar, and zsh is filling in a new ...
3
votes
2answers
227 views

Shell script wrapper to prevent running command with no arguments?

There is program I use, say xyz, that has undesirable effects if I run the command bare with no arguments. So I'd like to prevent myself from accidentally running the xyz command with no arguments ...
4
votes
2answers
439 views

Basic commands in Unix not working i.e: -bash: ls: No such file or directory

I'm new to Unix and in the process of installing a program for my dissertation I must have played with the PATH for the basic Unix commands such as ls. Every time I type ls and the directory name I ...
2
votes
2answers
83 views

Typing text from a shell script [duplicate]

I'm new to shell scripting. I'd like to know if there's a command similar to "echo" for displaying text in a terminal, but instead of simply displaying it immediately, it actually types it, like if ...
2
votes
2answers
6k views

Use awk to split line into array and use that array's values in calling shell

I am trying to use awk inside a bash script and do a rather common task: iterate well structured file lines and split them by a delimiter into an array. Here is a sample from the file: ...
0
votes
0answers
42 views

How to synchronize folder with TFS in linux

I am using TFS every where on CentOS and I want to run a service to listen on directory modifying this directory represent TFS local folder and for every (add or modify) it mirroring to TFS I tried ...
0
votes
1answer
223 views

Unable to override the JAVA home in opensuse 13.1

What I did : made an entry in both ~/.bash_profile ~/.profile export JAVA_HOME=/usr/java/jdk1.7.0_51 export PATH=$PATH:/usr/java/jdk1.7.0_51/bin still system points to some openJDK installed by ...
2
votes
2answers
3k views

grep output of expect script

I'm trying to run some expect language, and grep/parse the output all in one script. I want to grep the output of and look for "error" (I should note that standard linux commands like awk, sed, grep, ...
1
vote
2answers
21 views

Comparing value in same column and directing output to new column

I have my input file as DPortal=ECCN RemoteFile=4004_130122 0256 A02 141111 0940 29343414 11 110005 DPortal=ECCN RemoteFile=4004_130122 0256 A02 141111 2336 29843714 11 110006 DPortal=ECCN ...
6
votes
1answer
581 views

Escape sequences in output of script called from ncurses application

I'm currently running mcabber as my Jabber client (which uses ncurses) in a tmux session on my homeserver. Locally i run iTerm2 as a terminal emulator, which supports the triggering of growl ...
-1
votes
3answers
47 views

OR operator in bash scripting [duplicate]

This code generates a error line 3: [: missing `]'. So please anyone tell me that why i am getting such error.I am new in bash scripting. #!/bin/bash read x if [ $x == "Y" ] || [ $x == "y"] then ...
1
vote
2answers
35 views

Randomize arguments ( that hold color codes) from an array

I have the array (shown below) with arguments that hold color codes. The intended purpose of my script is to randomize those arguments when the user inputs "scriptname randoms Text" so that every time ...
2
votes
1answer
31 views

Error passing variable from bash to php

I have the following files: vars.txt C=1234567890 Ascript.php #!/usr/bin/php <?php var $C="$argv[1]"; echo "\n $C \n"; $con = mysql_connect('localhost','root','123') or die ("No connected"); ...
9
votes
3answers
9k views

Understanding backtick (`)

I am trying out the command $ b=5; echo `$b`; -bash: 5: command not found but it does not print 5 as it is supposed to. What am I missing here? What does ` (backquote/backtick) mean in bash? seems ...
0
votes
4answers
58 views

Make WGET available without path

I have ready bash script, which extensively uses wget command. Unfortunately wget is not available at standard path, but available at: /usr/custom/bin/wget I was able to make it usable w/o path in ...
4
votes
5answers
3k views

Progressbar in bash to visualize the time to wait

In a bash script sometimes you need the user to wait some seconds for a background process to finish. I usually use for example: sleep 10 How can I add a kind of progressbar to the script, so the ...
2
votes
2answers
121 views

Is there a special variable containing a case statement match

If you write a Bash case statement, can you get the current match without explicitly assigning it to a variable ? Consider case $(some subshell command sequence) in one) stuff ;; *) stuff ...
7
votes
1answer
870 views

Use the command bar in bash without I/O?

I really like the look of the output of bar But that script is only used for Input/Output operations. How can I use it as a replacement for sleep but with visual feedback? sleep 10
0
votes
1answer
1k views

Proper escaping of double quotations for curl post data?

I'm trying to test out a server, by sending it JSON data and reading the response. I need to POST data like {"item":"value with spaces"} but when I use curl I find that it sends the backslashes as ...
5
votes
3answers
96 views

Shell/Bash script: Properly drop privileges

Okay, first of all, I know this question has been asked a few times here, but the answers given did not entirely satisfy me. The situation is the following: I have written many scripts to automate ...
2
votes
3answers
18 views

how to run the dialog command with proccess

Please look on my code – ( bash script ) I want to display both dialogs on the screen on the same time, one dialog display the: tail –f from - /var/log/proccess1.log , and the second dialog ...
0
votes
1answer
29 views

Check for subdirectory

A)I used the following code to get the modified date of a file. But this is also selecting the subdirectories and thus returning an error. How van I fix this. for file in $1/*; do echo `stat ...
2
votes
1answer
554 views

How can I run as another user?

This is the bash code that should be runned. So first it substitutes the user to openproject and than runs all the code su openproject -c "bash -l" cd ~/openproject git checkout Gemfile.lock git ...
1
vote
2answers
50 views

How to delete a word next of last slash

I have the following path : $ vim /path/to/some/where If I press Ctrl + w, It removes entire text to first space. The result would be : $ vim How do I delete just the word next of last slash ...
0
votes
1answer
40 views

how to reboot multiple computer using bash loop from the txt file

can anyone knows how to reboot computer in just one line code of bash (by looping itself). The details will be get from the text file which are the IP Address of each computer. When the script gets ...
1
vote
1answer
63 views

How to round floating point numbers in shell?

How do I correctly round IEEE 754 floating point numbers on the command line? I want to specify the precision of the output number - the count of fractional digits. Rounding 6.66 to precision 1 ...
6
votes
1answer
154 views

Function that calls another function with list of arguments doesn't work

In my .bash_aliases I have defined a function that I use from the command line like this: search -n .cs -n .cshtml -n .html SomeTextIWantToSearchFor /c/code/website/ /c/stuff/something/whatever/ ...
0
votes
1answer
78 views

Bash error: “[y command not found” [duplicate]

I am trying to get this script to function correctly but I get ./passmark.sh line 7: [y command not found. Here is my script #!/bin/bash # A simple script to ask a user for a pass mark and then ...
2
votes
2answers
39 views

How to select unique array values?

I have an array and I want to get the unique 2nd members bash doesn't really have 2-dimensional array so I've defined it this way, using :: as the separator of the two elements: ruby_versions=( ...
0
votes
1answer
27 views

elif command is throwing error [closed]

Hi is the below elif command correct? elif [[ "${FILECOMMAND}" = "" ] && [[ -f ${ZIPFILE} ]||[ -f ${ZIPFILE3} ]]] I am getting an error when I run it.
0
votes
2answers
37 views

Cannot merge files using cat [duplicate]

I tried to open a lot of files (10,000+) with cat and them merging them into one like this: cat * > ~/Desktop/lol.xml But it returned this error: -bash: /bin/cat: Argument list too long This ...
1
vote
0answers
29 views

Automating sshfs not working

I want to mount a remote directory and I want to automate this. So I write below script which not working properly. #!/usr/bin/expect -f spawn sshfs vedams@192.168.5.109:/home/user /mnt/remote expect ...
27
votes
3answers
20k 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?
6
votes
1answer
3k views

How to execute a script in shell when a shortcut key is pressed

How could I execute a script in Shell when a shortcut key is pressed. Essentially what I need is when a shortcut key is pressed the script should read from a file and display that content in the ...