Linked Questions

285
votes
6answers
36k views

What's the difference between $(stuff) and `stuff`?

There are two syntaxes for command substitution: with dollar-parentheses and with backticks. Running top -p $(pidof init) and top -p `pidof init` gives the same output. Are these two ways of doing the ...
418
votes
17answers
208k views

Get exit status of process that's piped to another

I have two processes foo and bar, connected with a pipe: $ foo | bar bar always exits 0; I'm interested in the exit code of foo. Is there any way to get at it?
21
votes
4answers
13k views

bulk rename (or correctly display) files with special characters

I have a bunch of directories and subdirectories that contain files with special characters, like this file: robbie@phil:~$ ls test�sktest.txt test?sktest.txt Find reveals an escape sequence: ...
19
votes
6answers
3k views

Use system command instead of Bash builtin without specifying the full path

I use Bash as my interactive shell and I was wondering if there was an easy way to get Bash to run a system command instead of a shell builtin command in the case where they both share the same name. ...
4
votes
4answers
5k views

Finding duplicate users on CentOS

I'm using the following code to find the duplicate username. However, it gives an error. #!/bin/bash cat /etc/passwd | cut -f1 -d":" | /bin/sort -n | /usr/bin/uniq -c |\ while read x; do [ -z "${...
4
votes
2answers
7k views

Simultaneously check for empty output and successful exit status

I'd like to write the following test in an installer script1: if [ -n "`/etc/grub.d/30_os-prober`" ]; then install_dual_boot else install_linux_only fi However, it's also possible that 30_os-...
2
votes
3answers
4k views

Creating a new file inside awk but in different directory based on input field value

I am trying to work with awk datetime=`date +\%Y\%m\%d` logdatetime=`date +\%Y\%m\%d` foldermonth=`date +\%B_\%Y` folderday=`date +\%d` inputdir="~/sboper/Standalone/fsplit/GLMS" ...
-7
votes
1answer
7k views

Head and tail command

How can i do this exercise in unix? Create the following command: lshead.bash – list the first few lines of every file in a directory specified by the argument. This command should also allow options ...
0
votes
1answer
734 views

Unexpected end of file inside of my bash script [closed]

I have a script #Check the disk space before backups are taken echo "Checking Disk Space" df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output; echo $output ...
1
vote
1answer
57 views

Why is one of these date commands valid and the other not?

[user@mymachine folder]$ echo `date --date=tomorrow +%Y%m%d` 20160802 [user@mymachine folder]$ echo `date -d=tomorrow +%Y%m%d` date: invalid date `=tomorrow' I'm using Centos 5 if that makes any ...
1
vote
1answer
52 views

Script to see /mysqlshare is present in all list servers, doing only first iteration

I need to get /mysqlsharedetails from all the MySQL servers. I have written a script using a while read loop, but it's getting the details of only the first server, #!/bin/ksh file="/home/mysqladm/...