syntax

awk inside function causing errors

awk inside function causing errors I’m trying to add the following to my .bashrc: cpu_info() { top -b -n1 | grep Cpu(s) | awk ‘{print $2 + $4}’ } but bash is telling me: bash: .bashrc: line 131: syntax error near unexpected token `(‘ bash: .bashrc: line 131: ` top -b -n1 | grep Cpu(s) …

Total answers: 1

lsof output file descriptor with asterisk not documented

lsof output file descriptor with asterisk not documented When I run lsof I see the output java 1752736 user 9995u sock 0,8 0t0 1432559505 protocol: TCPv6 java 1752736 user *527u sock 0,8 0t0 1444900878 protocol: TCPv6 What does the * in front of the file descriptor indicate? Asked By: lfmunoz || Source Newer versions of …

Total answers: 1

mv multiple files on Linux vs. on Mac

mv multiple files on Linux vs. on Mac To move multiple files on Linux, one could use: mv -t DESTINATION file1 file2 Whereas on macOS it is mv file1 file2 DESTINATION Why is this difference? Is this a Bash vs. Zsh thing, or older vs. newer syntax, or what? Asked By: jsx97 || Source The …

Total answers: 2

How to make the (N) patterns of the zsh eatable by bash?

How to make the (N) patterns of the zsh eatable by bash? I am trying to develop a script which runs (and, ideally, does the same 🙂 ) in zsh and Bash. Problem is, that at a point, the zsh-specific part contains a pattern ending with (N). So: this_pattern*(N). In zsh, that makes the pattern …

Total answers: 2

Is there a good apt syntax for installing an approximate package version?

Is there a good apt syntax for installing an approximate package version? Sometimes I don’t immediately know the full package version details, but I do know which major.minor version I’m after- For example, say I have package foo-package with several versions of debs available in my repository, and I want to get 1.4.1~build1 while 1.5.1~build3 …

Total answers: 1

What does "*", "**", and "***" mean in Timeshift filters?

What does "*", "**", and "***" mean in Timeshift filters? When excluding a folder, Timeshift generates a filter rule of this format: /home/nils/.cache/*** What do the three stars mean? And what do two or a single star mean? Asked By: Nils Lindemann || Source Timeshift uses rsync. The pattern you show is an rsync pattern …

Total answers: 1

What is "in" in Bash?

What is "in" in Bash? I have encountered this in the syntax for case after calling help case and getting case WORD in [PATTERN [| PATTERN]…) COMMANDS ;;]… esac. There was a question, whether "in" is a bash operator, but answers were answering the script problem of the person rather than saying clearly whether there …

Total answers: 1

What does mean in bash and find?

What does mean in bash and find? I know that is an escape character, but when I write in bash, I have something like this: System-Product-Name:~$ > So bash waits for some instructions? When I use System-Product-Name:~$ > ls It is working. But when I use System-Product-Name:~$ cd Wideo > ls bash: cd: too many …

Total answers: 3

Dangers of executable file with '#' in name?

Dangers of executable file with '#' in name? This might be a FAQ–happy to have the question closed if it’s a dupe–but I’m not sure how to find it if so. I’d also be happy with an answer that simply told me how to find the relevant documentation on syntax. (man bash is an old …

Total answers: 2

How to search for a pattern with sed and replace another substring on that line

How to search for a pattern with sed and replace another substring on that line I need to find all lines in my data file that contain NO_ID and then replace the string "confirmed" by "to be confirmed". I tried this: sed ‘/NO_ID/, s/confirmed/to be confirmed/’ stats.txt which doesn’t seem to work. Asked By: elmo …

Total answers: 2

What does command eval "$(/opt/homebrew/bin/brew shellenv)" actually do?

What does command eval "$(/opt/homebrew/bin/brew shellenv)" actually do? Homebrew requires us to add eval $(/opt/homebrew/bin/brew shellenv) to ~/.zprofile. What does this actually evaluate to and what does this accomplish? I am a bit new to shell scripting. I know $var is used to refer to a variable named var but that’s about it. What is …

Total answers: 2

Confused about java -version

Confused about java -version For every program/utility on Unix, I would type the name of the program followed by –version to check its version, like so program –version If I understand correctly, the double dash — is used to specify a single option named version instead of -version, which would mean 7 options v,e,r,s,i,o,n. Why …

Total answers: 1

Test for a number in bash

Test for a number in bash Is this the correct way to test for a number, with double [[]] enclosing :digit: and single quotes surrounding the regex ? if [[ "$var" =~ ‘^[[:digit:]]+$’ ]]; then Asked By: Veak || Source It is not, as a simple test will show us: #!/bin/bash for var in 1 …

Total answers: 2

Compact form of a bash file extension test condition

Compact form of a bash file extension test condition I am testing whether arguments are not video files (.mp4, .mkv). Can I clean this so as to make it more compact test. if [[ ! "$1" == *.mp4 || ! "$1" == *.mkv ]]; then Asked By: Veak || Source Using a case statement is …

Total answers: 1

Unable to uncomment just the cron by matching the string MYAPP

Unable to uncomment just the cron by matching the string MYAPP Below is my existing cron which i wish to enable crontab -l ####Cron to auto restart MYAPP ###*/15 * * * * ansible-playbook /web/playbooks/detectMYAPP/va_action.yml | tee -a /web/playbooks/detectMYAPP/cron.out I wish to enable cron by matching app name MYAPP I use the below sed command …

Total answers: 2

Getting an error in the if condition

Getting an error in the if condition I am just checking whether the password contains a small and capital case letter, I am getting an error at line 19. myscript.sh: #!bin/sh read password conditionarr=(0 0) if [[ $password =~ [A-Z] ]] then condtionarr[1]=1 fi if [[ $password =~ [a-z] ]] then conditionarr[0]=1 fi if [ …

Total answers: 2

why head -5 /filepath and head -n 5 /filepath shows the same output?

why head -5 /filepath and head -n 5 /filepath shows the same output? I’m sorry for this silly question but i’m new to terminals and i don’t quite understand how we can pass a number of lines without an option. Even the man page says: -n, –lines=[-]NUM print the first NUM lines instead of the …

Total answers: 1