Tag Info

New answers tagged

3

STRING="abc" SUBST="ab" if [ `echo $STRING | grep -c $SUBST` = 0 ]; then echo false else echo true fi


4

[[ "ab" =~ "bcd" ]] [[ "ab" =~ "abc" ]] the brackets are for the test, and as it is double brackets, it can so some extra tests like =~. So you could use this form something like var1="ab" var2="bcd" if [[ "$var2" =~ "$var1" ]]; then echo "pass" else echo "fail" fi Edit: corrected "=~", had flipped.


4

You can use the form ${VAR/SUBS} where VAR contains the bigger string and SUBS is the substring your are trying to find: my_string=abc substring=ab if [ "${my_string/$substring}" = "$my_string" ] ; then echo "${substring} is not in ${my_string}" else echo "${substring} was found in ${my_string}" fi What ${VAR/SUBS} does is remove the first occurrence ...


1

Try this: man * | col -b | grep *


0

http://www.commandlinefu.com/commands/view/4460/pipe-output-to-notify-send says echo 'information overlord' | while read OUTPUT; do notify-send "$OUTPUT"; done


1

Try this: #!/bin/bash unset password prompt="Enter Password:" while IFS= read -p "$prompt" -r -s -n 1 char do if [[ $char == $'\0' ]]; then break fi if [[ $char == $'\177' ]]; then prompt=$'\b \b' password="${password%?}" else prompt='*' password+="$char" fi done echo " " echo "Done. ...


1

It seems your .bashrc file contains the lines without the double quotes: alias android-connect=mtpfs -o allow_other /media/GalaxyNexus alias android-disconnect=fusermount -u /media/GalaxyNexus Open the file in an editor and remove the offending lines.


1

That's why we use quotes. ... "$1"


1

I think you better to use a launcher file for your script by creating a ~/Desktop/ssh_home.desktop with the following contents: [Desktop Entry] Version=1.0 Exec=/home/yourname/bin/ssh_home.sh Name=SSH Server GenericName=SSH Server Comment=Connect to My Server Encoding=UTF-8 Terminal=true Type=Application Categories=Application;Network; That way you will have ...


-1

open a terminal sh '/home/yourname/Desktop/yourfile' or drag and drop it...


0

i figured it out. i needed to change this line: for INF in *.mkv to point directly at the folder: for INF in /mnt/sdb1/temp/*.mkv


1

I ran into this problem yesterday while trying to install IRAF 2.14 and x11IRAF 1.3.1 on Xubuntu 12.10. From this helpful post, I realized that the issue was that xgterm needs the following 32bit libraries that were not by default installed on my system: libx11-dev ia32-libs These libraries are in the Ubuntu repositories, so an apt-get should do the ...


0

I got same errors I then did the following sudo bash echo 0 > /proc/sys/kernel/hung_task_timeout_secs This eliminates the permission error, but not sure it will eliminate your problem.


3

From the Bash manual: When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes ...


1

echo $0 will return the script name which is being executed, when this command is executed within a shell script. In a terminal, it will return the type of shell being used. You are using bash shell. You need to add this line export LD_LIBRARY_PATH=/home/dspies/workspace/hdf5-1.8.11-linux-shared/lib to ~/.bash_profile file. EDIT: You may find the ...


0

It will really prevent that feature to work since you are indirectly specifying in "Open Terminal Here" to open the terminal in the current directory. That's how it should work. The cd in .bashrc will only work if you run a gnome-terminal not from the context option you mentioned. As a solution to your problem, you can add an alias to cd to the directory ...


1

In recent versions of GNOME Terminal the --working-directory argument can be used to set the working directory of the terminal. gnome-terminal --working-directory=/foo/bar


1

Grep your syslog for messages like; crond: (*system*) BAD FILE MODE the files need to be restricted to (is sufficient) at 644): chmod 0644 /etc/cron.d/my_crontab


9

Add shopt -s autocd to your ~/.bashrc. Also, you might want to run man shopt in terminal for more useful options.


3

Switch to a bash function: function changelc { export PS1="$1" } And then, when tested: $ changelc "rawr: " rawr:


-1

Did you try with `longlocation` Note that they're not single or double quotes, but the backtick.


1

I found the solution here: http://stackoverflow.com/questions/9652126/bashrc-profile-is-not-loaded-on-new-tmux-session-or-window-why and here: http://apple.stackexchange.com/questions/12993/why-doesnt-bashrc-run-automatically I needed to add source ~/.bashrc to the end of my .bash_profile.


0

There are two steps to this. First, you need to tell xterm to allow it to happen at all, because by default it ignores requests by hosted programs to resize the window. Add this to your ~/.Xdefaults: xterm*allowWindowOps: true For this to take effect, you either have to log out, or run: xrdb ~/.Xdefaults Then launch a new xterm, and in your bash ...


1

It is located in: ~/.bash_history


0

You could start your program with screen, and then detach from the screen, that way the program will not be suspended.


0

This may not a real answer. I wonder what the different of Bash between Ubuntu with MSYS. I running MSYS and when i run Application/Chrome &, it immediately go to background process. I can use the MSYS bash as next prompt start blinking. And are this questions Move running program to background with similar intents?


0

I'm doing: ( sysctl vm.swappiness=10 ) > /dev/null if [[ `grep "vm.swappiness=" /etc/sysctl.conf | wc -l` -eq 0 ]]; then echo "vm.swappiness=60" >> /etc/sysctl.conf fi sed -i -r 's~^vm.swappiness[[:blank:]]*=[[:blank:]]*[0-9]*$~vm.swappiness=10~' /etc/sysctl.conf


2

It could also be that root:root owns your .bash_history, in that case you need to: $chown user:user .bash_history


0

Log in on a tty1 (Ctrl+Alt+F1) and run these commands: export PATH="/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$PATH" sudo chown -R $USER:$USER /home/$USER/ You can replace $USER with your actual username. Now, try logging in again.


2

If the first line of /usr/bin/diffuse looks like: #!/usr/bin/env python it will run in Python inside your virtualenv. Most Python applications should set it to: #!/usr/bin/python which will run it with the system Python. If this is wrong, it might be a bug either in Diffuse or in its packaging in Debian/Ubuntu.


1

Type the following command: sudo gedit /etc/bash.bashrc Look for these lines: # enable bash completion in interactive shells # if ! shopt -oq posix; then # if [ -f /usr/share/bash-completion/bash_completion ]; then # . /usr/share/bash-completion/bash_completion # elif [ -f /etc/bash_completion ]; then # . /etc/bash_completion # fi # fi ...


1

The SHELL variable (along with some other variables, such as HOME and USER) is set by the process that logs you in. It is set to the login shell value set in the passwd database (/etc/passwd). It is not meant to reflect the shell you're currently using. screen uses the SHELL variable to determine what shell to run inside the screen, so you can override that ...


1

Depends on how you write the loop; unless you background the rsync commands with the & symbol, the rsync commands will run in sequence. rsync will return a useful exit status. These are listed in rsync's manual page. man rsync | less '+/^EXIT VALUE'. You have to decide whether you want to abort the whole script when one fails, or attempt to run the ...


0

HISTCONTROL only affects new hist lines. What I think the author what is a way to edit the existing hist file. nl ~/.bash_history | sort -k 2 | uniq -f 1 | sort -n | cut -f 2 > temp_file followed by temp_file > ~/.bash_history This should preserve line order, while removing dups from the existing hist file. May leave behind ghost time-stamps, if you ...


0

"erasedups" should do the trick, did you source .bashrc after your change? Can you please echo $HISTCONTROL and tell us the output? Also: be sure you actually want to do that on .bashrc and not in .bash_profile instead... Basically, what I'm suspecting is that you simply don't have HISTCONTROL on your environment.


0

It's not a bug with bash, there's just not any safe way to put a bash array in the environment. As for workarounds, that depends on what you're trying to achieve with exporting arrays in the first place. One possible workaround, for some cases, is to dump the array to a file and source that file where you need it. astr=(a "b c" d) declare -p astr > ...


0

I had the similar question, until I found this. http://blog.e-thang.net/2012/08/14/tmux-and-bash-tab-completion/ Pretty good, colorful, explanation. Reference: /usr/share/byobu/keybindings/f-keys.tmux /usr/share/byobu/keybindings/f-keys.tmux.disable


1

Install CMake and cd to the build directory and command: cmake . If you want to have more control install cmake Gui


1

I developed a simple ping-based nodejs script that tests the servers listed on mirrors.ubuntu.com/mirrors.txt and returns the fastest one: sudo npm install -g ffum ffum Please let me know if you find it useful or have any suggestions (=


1

With this much fudge, I'd strongly consider starting a new bashrc. Even without a correct $PATH, the following should work: /bin/mv ~/.bashrc{,.BAK} /bin/cp /etc/skel/.bashrc ~ Of course, depending on how messed up things are, you might need to replace ~ with the path to your home. Try it and see. You'll need to run /usr/bin/reset which should reload ...


1

I found these in penguinparens.blogspot.com: The partition your script lives on may be mounted with the "user" option set. "user" implies "noexec" (see the manpage for "mount"), which is going to keep you from running executables. And while running a binary executable from this kind of partition fails more clearly, trying to run a script with a ...


0

Substring has more function, as the name says it can be used to take a substring of a variable. For example var='123456789' echo ${var:2:4} Will output 3456 While using array you have to use substring for accessing array variables. For example a[0]=0 a[1]=1 a[2]=2 echo $a will print 0. echo "$a[1]" output 0[1] So accessing array variable at ...


0

kdialog Development/Tutorials/Shell Scripting with KDE Dialogs : http://techbase.kde.org/Development/Tutorials/Shell_Scripting_with_KDE_Dialogs Example 6: Password Dialog Using a Shell Variable Instead of saving the result in a file, you can also use a shell variable. Note that you need to use the "backtick" notation - this key is normally found on ...


0

You might have got the answer by now, but i am still posting it here. You can use expect command to send the password (stored in the 'passwd' variable) to the terminal when the required prompt appears. A good tutorial can be seen here.


1

You just have to use quotes on the variable BASH_VERSION to use -n if [ -n "$BASH_VERSION" ];then echo "this is bash"; else echo "this is dash"; fi


1

You can do that with su or sudo, no need for both. sudo -H -u otheruser bash -c 'echo "I am $USER, with uid $UID"' The relevant parts of man sudo: -H The -H (HOME) option requests that the security policy set the HOME environment variable to the home directory of the target user (root by default) as ...


0

The solution is not straightforward. It requires start of script at X login and waiting till the and of X session. Fortunately we have inotify and pid of gnome-session. Variety process should already be killed properly at the time of script execution. Install inotify-tools package. Create or modify ~/.xprofile script and add to it following line sh ...


0

You could use Aptitude's why command: for x in $(apt-mark showmanual) do aptitude why ${x} | grep -q ' Depends ' && apt-mark auto ${x} done Not tested, because it's not something I want to (have to un-)do on my machine.


1

Run the commands first, then check if at least one of them succeeded. #!/bin/bash success=0 do_something arg1 && success=1 do_something arg2 && success=1 do_something arg3 && success=1 if ((success)); then printf 'Success! At least one of the three commands succeeded\n' fi


0

Check out terminology, the console from Enlightenment. It's capable of what you are asking...see this video: http://www.enlightenment.org/p.php?p=about/terminology Not sure how much is capable outside of Enlightenment, but they have a ppa for it. https://launchpad.net/~efl/+archive/trunk



Top 50 recent answers are included