Skip to main content

All Questions

Tagged with
148 votes
11 answers
55k views

What is the difference between $* and $@?

Consider the following code: foo () { echo $* } bar () { echo $@ } foo 1 2 3 4 bar 1 2 3 4 It outputs: 1 2 3 4 1 2 3 4 I am using Ksh88, but I am interested in other common ...
rahmu's user avatar
  • 20.1k
129 votes
4 answers
52k views

Why does parameter expansion with spaces without quotes work inside double brackets "[[" but not inside single brackets "["?

I'm confused with using single or double brackets. Look at this code: dir="/home/mazimi/VirtualBox VMs" if [[ -d ${dir} ]]; then echo "yep" fi It works perfectly although the string contains a ...
Majid Azimi's user avatar
  • 3,108
22 votes
2 answers
1k views

Why escape trivial characters in shell script?

I just opened a legacy shell script (written in old ksh88 on Solaris) and found the following repeated all throughout the code: [ -f $myfile ] && \rm -f $myfile The escaping backslash ...
rahmu's user avatar
  • 20.1k
10 votes
2 answers
24k views

How do I escape a sub-directory name with an ampersand in it?

Running a kornshell and trying to traverse a directory tree. Want to cd to a sub-directory named as follows: -3ab_&_-3dc.img My question is HOW do I need to escape the ampersand in this name? I'...
RCinICT's user avatar
  • 101
8 votes
4 answers
49k views

using awk to split a line on single spaces not multiples

I'm trying to split a line that I have no control over the format of. If parameter 7 and 8 are missing which is possible they will be replaced by a space so I would end up with, field1 field2 field3 ...
dazedandconfused's user avatar
5 votes
3 answers
3k views

quotes inside backticks inside quotes in ksh

I'm trying to get the file of the current date with the following command in HP-UX Unix: $ ls -lrt ABC.LOG* |grep "`date +"%b %d"`" But, it's giving me the error: ksh: : cannot execute grep: can't ...
ashish_k's user avatar
  • 375
3 votes
1 answer
404 views

Why is "${1-"$var"}" (option 6 down below) not mentioned in POSIX?

The only reference I could find in the spec is this: It would be desirable to include the statement "The characters from an enclosed "${" to the matching '}' shall not be affected by ...
QuartzCristal's user avatar
3 votes
2 answers
1k views

issues with GNU tail -f and combination of commands

$ tail -f /logs/filename.log | awk '!(/list)' I am able to run this command in GNU Linux flavour But when I written in a script it is not working. test.ksh: variable="/logs/filename.log | awk '!(/...
Manoj's user avatar
  • 31
2 votes
2 answers
734 views

Meaning of \ before environment variable

In ksh on an old Solaris box I used: export PS1="$PWD $" to set the prompt to the current directory. It works great until you cd elsewhere, then you see that it's not evaluating PWD each time. I ...
user avatar
2 votes
2 answers
137 views

Awk not rendering any result

My goal is to get the file created in the current month in a directory. It seems that the command is correct but not rendering any result: Date=`date '+%b'` echo $Date Oct ls -l | awk -v d="$Date" ...
Ram's user avatar
  • 383
1 vote
2 answers
32k views

How to compare strings in ksh

I want to check the result of a job and execute an action on FAILED. First: I grep the last word of the line in my application logfile (for the recent processed file ($processedfilename)): check1=$(...
Vince's user avatar
  • 23
1 vote
2 answers
1k views

Unable to store ascii value in a variable

I am trying to convert hex to decimal to ascii and store it in a variable. I am using the following code. HEX=30 DEC=`printf "%d\n" 0x${HEX}` echo "$DEC" ASC=`printf \\$(printf '%03o' $DEC)` echo "$...
ayrton_senna's user avatar
  • 1,091
1 vote
1 answer
287 views

UNIX KSH - Using double quotes or no quotes when assigning strings with wildcard to a variable?

I am new to UNIX and currently working on a shell script where I will be receiving files with names such as abc_123_date.zip so the file names will be abc_123_12312005. Instead of hardcoding abc_123_*....
ganq's user avatar
  • 11
1 vote
3 answers
1k views

Quoting in command substitution

The command pdftk FileOne.pdf "File two.pdf" output Combined.pdf works as expected, merging PDF's One and Two. However, if I put the filenames in a file FileOne.pdf "File Two.pdf" and ...
Michael's user avatar
  • 11
1 vote
1 answer
68 views

Why does enclosing a command in double quotes affect aliases?

I have an alias rm='/bin/rm -i' and I know that if I type "rm" filename in the command line, the alias will be ignored somehow and the normal rm command without the -i flag will be called, ...
BrassPandaSax's user avatar

15 30 50 per page