Posts

Showing posts with the label bash

what is the difference between $1 and “$1” in bash script? [duplicate]

what is the difference between $1 and “$1” in bash script? [duplicate] This question already has an answer here: example while [ -n "$1" ] do something done can i write $1 instead of "$1" ? And what is the difference between user=alexander and user="alexander" ? Thanks $1 "$1" user=alexander user="alexander" This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. The shell does substantially more processing on unquoted strings than on quoted ones (not just splitting them up on whitespace or characters in IFS, but also expanding each of the post-split components as a glob) -- and in 99% of cases that processing is undesired. Missing quotes are probably responsible for more BashPitfalls entries than any other single class of error. – Charles Duffy Jun 30 at 3:33 ...

Weird Vim configuration on Ubuntu Bash for Windows

Weird Vim configuration on Ubuntu Bash for Windows First screenshot Second Screnshot I am using Ubuntu Bash for Windows and installed the ultimate vimrc from https://github.com/amix/vimrc However, now I get this weird highlighting over my code in vim. Any suggestions on how to get rid of it? set t_Co=256 may fix the problem with the background color. – Sergio Jun 30 at 6:04 set t_Co=256 By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Sharing PATH Variable Windows Subsystem for Linux (WSL) [on hold]

Sharing PATH Variable Windows Subsystem for Linux (WSL) [on hold] So I am trying to link the PATH variables for Java (and Python) to the Windows Linux bash shell I've tried following the directions on here: https://blogs.msdn.microsoft.com/commandline/2017/12/22/share-environment-vars-between-wsl-and-windows/ for /p with the path that I already have on windows: C:Program Files (x86)Common FilesOracleJavajavapath C:Program Files (x86)Common FilesOracleJavajavapath I did everything the same except first define TRANSLATABLEPATH as my the linux mnt path and then when im in cmd, the windows path What am I doing wrong? Edit: See comment but I basically set TRANSLATABLEPATH and export WSLENV=TRANSLATABLEPATH/p Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit th...

bash: Get last line of a huge gziped file

bash: Get last line of a huge gziped file In a database backup process I generate a text dumpfile. As database is quite huge, dump file is huge too so I compresses it with gzip. Compression is done inline while dump is generated (thanks Unix pipe !). At the process end, I check dump file validity by watching the last line and check the "Dump completed" string presence. In my script I do it by extracting last line into a variable: str=`zcat ${PATHSAVE}/dumpFull.sql.gz | tail -n1` As database dump file is huge (currently more than 200Gb) this end process check take huge time to run (currently more than 180 minutes). I'm searching a way to extract quicker the last line of my .gz file ... any idea anyone ? Note 1: For explain context, we can say database is MySql community, backup tool is mysqldump, generated dumpfile is a full text file. OS is CentOs. Backup script is Bash shell script. Note 2: I'm aware about Percona xtraBackup but in my case I want to use mysqldump f...

Appending with 2> and with >>

Appending with 2> and with >> Why do some scripts use 2> instead of >> ? Is the 2 just a multiplier of the > 's ? 2> >> > Read the Bash manual page – Some programmer dude Jun 29 at 10:45 3 Answers 3 1>> and 2>> are redirections for specific file-descriptors, in this case the standard output (file descriptor 1) and standard error (file descriptor 2). 2> Will output the error in the script to a file. ">>" Will append the output of a command to an existing file. If file doesn`t exists then it will create the file add the output to the file. See this link => https://unix.stackexchange.com/questions/183125/what-does-1-and-2-mean-in-a-bash-script For 2> means you are re-directing ...

Can't get result from grep in bash loop

Can't get result from grep in bash loop I'm trying to get info from log files using grep + tail -1: #!/bin/bash # declare an array called array and define 3 vales array=( 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ) array2=( 00 30 ) for i in "${array[@]}" do for j in "${array2[@]}" do output=$(grep filtered /home/pavel/hasoffers_api/logs/tabatoo2_20180627$i$j* | tail -1) echo /home/pavel/hasoffers_api/logs/tabatoo2_20180627$i$j* echo "$output" done done this outputs just empty string, but I definitely know that phrase "filtered" is in the logs. What can be the problem? I tried several variations of the same script but it just returns empty string. Thanks! I think the script looks ok. The only explanation I see is that the string "filtered" is not in the logs or there's no files named ".../t...

Executing all files inside a folder in Python

Executing all files inside a folder in Python I have 20 Python files which is stored inside a directory in ubuntu 14.04 like 1.py, 2.py, 3.py , 4.py soon i have execute these files by "python 1.py", "python 2.py" soon for 20 times. is their a way to execute all python files inside a folder by single command ? 4 Answers 4 find . -maxdepth 1 -name "*.py" -exec python3 {} ; This will eventually recurse in subdirectories, which might not be what the OP wants. – bruno desthuilliers Jun 29 at 11:23 Added maxdepth 1 – RedEyed Jun 29 at 11:28 maxdepth 1 use p...

MacOS Terminal is not showing any $PATH

MacOS Terminal is not showing any $PATH no bash command was working in my terminal, so I tried to reset my $PATH and somehow screwed it up more. Any help! -bash: export: `/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/mysql/bin/': not a valid identifier Roopalis-MacBook-Air:~ roopa$ Roopalis-MacBook-Air:~ roopa$ echo $PATH Roopalis-MacBook-Air:~ roopa$ Roopalis-MacBook-Air:~ roopa$ Try this: export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/mysql/bin/ – KeyMaker00 Jun 29 at 9:42 Thanks! it worked. – roopa saxena Jun 29 at 10:13 Unfortunately, the problem continues to exists. I closed the terminal and reopened it and got the same problem. :( –...

How to get similar behaviour like the default CTRL+T binding in fzf with a custom search command?

How to get similar behaviour like the default CTRL+T binding in fzf with a custom search command? This question is (presumably) about bash and readline keybindings and how to customize them. I would like to create an alias like this: alias listvids="rg -g '*.{mkv,mp4,ogv}' --files 2> /dev/null | fzf to list certain video files in the current directory tree and pipe the input to fzf for fuzzy searching the results, which does work. fzf But then I would like the command to act "the same as" the default CTRL-T binding defined in ~/.fzf/shell/keybindings/key-bindings.bash , meaning it should paste the selected path from the fzf list into the command line when hitting enter. ~/.fzf/shell/keybindings/key-bindings.bash With the above command, when I hit enter on a path, it just gets echoed at the command line but does not get inserted into the prompt. I tried something like alias listvids="rg -g '*.{mkv,mp4,ogv}' --files 2> /dev/null | fzf --bind=ctr...