Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Incorrectly using 'ls' in if/then alias Post 302806773 by coldcoffeecup on Monday 13th of May 2013 04:09:05 PM
Old 05-13-2013
Incorrectly using 'ls' in if/then alias

I have an alias defined in which I wish to print the contents of a specific directory using 'ls' based on the if/then condition. The if/then conditions are being correctly evaluated, and the 'ls <path>' result is correct (tested directly in a terminal) although for some reason it seems the 'ls <path>' command isn't be executed. The <path> contents are not displayed. The only "workaround" I've found is to allow the alias to change the directory, and then call 'ls <path>' outside of the if/then logic. The alias is defined as follows (syntactically equivalent example):

Code:
alias mydir  'if ($a == "abc" || $a == "def") then
                        ls /$a/disks/abc/ \
                else if ($a == "ghi" || $a == "jkl") \
                        ls /$a/disks/def/ \
                else \
                        echo "Unrecognized var $a" \
                endif'

Any idea why the contents of the directory are not being listed? Thanks in advance for any suggestions.

/edit: added code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Writing to a log file incorrectly

I have this script: #!/bin/ksh ######### Environment Setup ######### PATH=/gers/nurev/menu/pub/sbin:/gers/nurev/menu/pub/bin:/gers/nurev/menu/pub/mac :/gers/nurev/menu/adm/sbin:/gers/nurev/menu/adm/bin:/gers/nurev/menu/adm/mac:/ge... (5 Replies)
Discussion started by: heprox
5 Replies

2. Linux

Hostname displays incorrectly

hiii, in many of the linux machines i have tried this but the result is the same everywhere. if there are double letters in a hostname then that is displayed as single letter. e.g. if hostname is set to nepttune then login into the shell will display : NEPTUNE(admin)@/ $ hostname... (15 Replies)
Discussion started by: shamik
15 Replies

3. UNIX for Dummies Questions & Answers

PATH variable set incorrectly?

I've noted that in order to use commands like ifconfig, I have to prefix the commands with the directory. /etc/profile shows that the paths should be part of the PATH environment variable; any idea where the bug is? :confused: # /etc/profile # System wide environment and startup... (1 Reply)
Discussion started by: jon80
1 Replies

4. UNIX for Dummies Questions & Answers

character displayed incorrectly by ftp

Hi there, I have a ftp server called atlantis. Because of the f...g french characters, I noticed something very weird. Depending on what program I use (ftp, lftp or ssh) the same character is displayed as three different ways. On my local computer, the file is correctly displayed as "modéles".... (1 Reply)
Discussion started by: chebarbudo
1 Replies

5. Forum Support Area for Unregistered Users & Account Problems

For users incorrectly rejected as a spammers

There was a problem with the site servicing our spam address checking. As a result all registrations were being rejected. If you have encountered this problem please try again and you should be permitted to join. (0 Replies)
Discussion started by: reborg
0 Replies

6. Shell Programming and Scripting

Totals in a file - incorrectly displaying

Afternoon, I have a script which creates/modifies data into a formatted csv. The trailer record should display 2 columns, the first is a static entry of "T" to identify it as a trailer record. The 2nd is a total of amounts in a column throughout the entire file. My total isn't displaying... (8 Replies)
Discussion started by: mcclunyboy
8 Replies

7. UNIX for Dummies Questions & Answers

Strings comparing incorrectly

Hello I'm very new to Linux and shell scripting so I only know basic stuff. I'm making a script with the purpose of finding the longest string or word in a file. Here's what I got so far: #!/bin/bash longest="" for i in $(strings -n $1); do if ] then longest=$i fi done echo $longest... (4 Replies)
Discussion started by: SCB
4 Replies

8. UNIX for Dummies Questions & Answers

Create alias files (not alias commands)

If one: $ find -name 'some expression' -type f > newfile and then subsequently wants to create an alias file from each pathname the find command retrieved and the > placed within 'newfile', how would one do this? Ideally, the newly created alias files would all be in one directory. I am... (3 Replies)
Discussion started by: Alexander4444
3 Replies

9. Shell Programming and Scripting

Bash string variable outputting incorrectly

Hello All, I am learning BASH scripting and I would appreciate any help with a small problem I am having... I am writing a script that builds a simple hosts file for DNS reasons related to a piece of software called netdb by parsing another application's config files for IP's and their... (4 Replies)
Discussion started by: Wesley545
4 Replies

10. UNIX for Beginners Questions & Answers

Ls incorrectly says file not found in sftp.

Hi all When I sftp to an Oracle cloud server, to a folder where there are more than 10k files, and list a small subset of files, it works OK. When I try list more than 10k files, it says file not found. Example output below. (FYI ls/mget with 6k files works OK on this server) Has anyone... (3 Replies)
Discussion started by: pdinsdale
3 Replies
praliases(1)						      General Commands Manual						      praliases(1)

NAME
praliases - print system-wide sendmail aliases SYNOPSIS
file] file] [key ...] DESCRIPTION
prints out the contents of the alias data base used by to resolve system-wide mail aliases. The alias data base is built with the command or See sendmail(1M). The options are: Read the configuration file specified with this option instead of the default configuration file. Accesses the alias database built from file with the command If this option is not used, accesses the database built from the default alias file Note that accesses the database, not the alias file itself. If the alias file has changed since the alias database was last built, natu- rally the output of cannot match the contents of the alias file. Each key argument, if any, is looked up in the alias database. prints out the aliases to which each key expands in the form: where mailing list can be a comma-separated list of addresses to which the key resolves. Note can be used by privileged users only. RETURN VALUE
The utility exits with 0 on success, and >0 if an error occurs. DIAGNOSTICS
key was not found in the alias database. EXAMPLES
The output reveals that is aliased to is aliased to and that there is no alias for the key WARNINGS
Because supports NIS aliases, some NIS key-words may appear in the output. These key-words, which include and may be safely ignored; they merely indicate that is properly updating the alias database. AUTHOR
was developed by the University of California, Berkeley. FILES
default alias file default alias database SEE ALSO
sendmail(1M). praliases(1)
All times are GMT -4. The time now is 01:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy